Documentation ¶
Overview ¶
The nn package contains code for building a neural network and other related functions needed to run them.
As of now, the list of functionality supported is layers with flat and convolutional layers being a work in progress; activation layers with functions like Tanh, Sigmoid, ReLu, Arctan; and loss functions like MSE, RMSE, and Huber.
Index ¶
- func Arctan(input *mat.Dense) *mat.Dense
- func ArctanDeriv(input *mat.Dense) *mat.Dense
- func Gaussian(input *mat.Dense) *mat.Dense
- func GaussianDeriv(input *mat.Dense) *mat.Dense
- func Hmse(y_true, y_pred *mat.Dense, params []float64) float64
- func HmseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
- func Huber(y_true, y_pred *mat.Dense, params []float64) float64
- func HuberDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
- func Linear(input *mat.Dense) *mat.Dense
- func LinearDeriv(input *mat.Dense) *mat.Dense
- func Mae(y_true, y_pred *mat.Dense, params []float64) float64
- func MaeDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
- func Mse(y_true, y_pred *mat.Dense, params []float64) float64
- func MseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
- func ReLu(input *mat.Dense) *mat.Dense
- func ReLuDeriv(input *mat.Dense) *mat.Dense
- func Rmse(y_true, y_pred *mat.Dense, params []float64) float64
- func RmseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
- func Sigmoid(input *mat.Dense) *mat.Dense
- func SigmoidDeriv(input *mat.Dense) *mat.Dense
- func Tanh(input *mat.Dense) *mat.Dense
- func TanhDeriv(input *mat.Dense) *mat.Dense
- type Activation
- type ActivationLayer
- type ConvolutionalLayer
- type DenseLayer
- type FlattenLayer
- type Layer
- type Loss
- type LossBwd
- type LossFwd
- type Network
- func (net *Network) AddLayer(layerType, activationType string, output_nodes int)
- func (net *Network) Fit(x_train, y_train [][]float64, epochs int, learning_rate float64, debug bool)
- func (net *Network) Predict(input [][]float64) [][]float64
- func (net *Network) SetLoss(lossType string, params []float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HmseDerivative ¶
HmseDerivative returns the derivative matrix of the half mean squared error given `y_true` and `y_pred` matrices.
func Huber ¶
Huber returns the pseudo-huber loss given `y_true` and `y_pred` matrices. Params[0] represents the provided delta value.
func HuberDerivative ¶
Huber returns the derivative matrix of the pseudo-huber loss given `y_true` and `y_pred` matrices. Params[0] represents the provided delta value.
func MaeDerivative ¶
MaeDerivative returns the derivative matrix of the mean absolute error given `y_true` and `y_pred` matrices. The derivative defaults to 1 when y_pred = y_true due to not being differentiable.
func MseDerivative ¶
MseDerivative returns the derivative matrix of the mean squared error given `y_true` and `y_pred` matrices.
func RmseDerivative ¶
RmseDerivative returns the derivative matrix of the root mean squared error given `y_true` and `y_pred` matrices.
Types ¶
type Activation ¶
Activation defines a type for any activation function.
type ActivationLayer ¶
type ActivationLayer struct { ACTIVATION Activation ACTIVATIONDERIV Activation // contains filtered or unexported fields }
ActivationLayer implements the Layer interface for an Activation layer in a neural network.
func NewActivationLayer ¶
func NewActivationLayer(activation Activation, activationDeriv Activation) *ActivationLayer
NewActivationLayer returns a new instance of an activation layer.
func (*ActivationLayer) BackPropagation ¶
func (layer *ActivationLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense
BackPropagation implements the Layer interface and returns a matrix after performing the derivative activation function on the layer values.
func (*ActivationLayer) ForwardPropagation ¶
func (layer *ActivationLayer) ForwardPropagation(input *mat.Dense) *mat.Dense
ForwardPropagation implements the Layer interface and returns a matrix after performing the activation function on the layer values.
type ConvolutionalLayer ¶
ConvolutionalLayer implements the Layer interface for a convolutional layer (CURRENT WIP).
func NewConvolutionalLayer ¶
func NewConvolutionalLayer(input_size int, output_size int) *ConvolutionalLayer
NewConvolutionalLayer returns a new instance of a convolutional layer (CURRENT WIP).
func (*ConvolutionalLayer) BackPropagation ¶
func (layer *ConvolutionalLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense
BackPropagation implements the Layer interface and returns the error matrix after performing back propagation (CURRENT WIP).
func (*ConvolutionalLayer) ForwardPropagation ¶
func (layer *ConvolutionalLayer) ForwardPropagation(input *mat.Dense) *mat.Dense
ForwardPropagation implements the Layer interface and returns a matrix after performing forward propagation (CURRENT WIP).
type DenseLayer ¶
type DenseLayer struct {
// contains filtered or unexported fields
}
DenseLayer implements the Layer interface for a Dense layer in a neural network.
func NewDenseLayer ¶
func NewDenseLayer(input_size int, output_size int) *DenseLayer
NewDenseLayer returns a new instance of a dense layer.
func (*DenseLayer) BackPropagation ¶
BackPropagation implements the Layer interface and returns the error matrix after performing back propagation.
func (*DenseLayer) ForwardPropagation ¶
func (layer *DenseLayer) ForwardPropagation(input *mat.Dense) *mat.Dense
ForwardPropagation implements the Layer interface and returns a matrix after performing forward propagation.
type FlattenLayer ¶
ConvolutionalLayer implements the Layer interface for a flat layer (CURRENT WIP).
func NewFlattenLayer ¶
func NewFlattenLayer(input_size int, output_size int) *FlattenLayer
NewFlattenLayer returns a new instance of a flat layer (CURRENT WIP).
func (*FlattenLayer) BackPropagation ¶
func (layer *FlattenLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense
BackPropagation implements the Layer interface and returns the error matrix after performing back propagation (CURRENT WIP).
func (*FlattenLayer) ForwardPropagation ¶
func (layer *FlattenLayer) ForwardPropagation(input *mat.Dense) *mat.Dense
ForwardPropagation implements the Layer interface and returns a matrix after performing forward propagation (CURRENT WIP).
func (*FlattenLayer) GetShape ¶
func (layer *FlattenLayer) GetShape() (int, int)
GetShape returns the flat layers dimensions
type Layer ¶
type Layer interface { ForwardPropagation(input *mat.Dense) *mat.Dense BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense }
Layer is a representation for different neural network layers, which require the functions ForwardPropagation and BackPropagation.
type LossFwd ¶ added in v0.3.0
LossFwd defines a type for any loss function for forward propagation.
type Network ¶
Network represents the neural network model specifics and related helper functions for loss.
func (*Network) AddLayer ¶
AddLayer appends to `LAYERS` in the network given `layerType`, `activationType`, and output neurons.
func (*Network) Fit ¶
func (net *Network) Fit(x_train, y_train [][]float64, epochs int, learning_rate float64, debug bool)
Fit trains the neural network provided training data, the number of epochs, and learning rate. If `debug` is true, then the error at each epoch is printed in terminal.