nn

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 5 Imported by: 0

README

Neural Network Package

WIP

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(fn func(x float64) float64, input *mat.Dense) *mat.Dense

*

  • Apply()
  • Helper that takes a function as a parameter to perform on the layer input

func Arctan

func Arctan(input *mat.Dense) *mat.Dense

*

  • Arctan Activation Funcs

func ArctanDeriv

func ArctanDeriv(input *mat.Dense) *mat.Dense

func Gaussian

func Gaussian(input *mat.Dense) *mat.Dense

*

  • Gaussian Activation Funcs

func GaussianDeriv

func GaussianDeriv(input *mat.Dense) *mat.Dense

func Hmse

func Hmse(y_true, y_pred *mat.Dense, params []float64) float64

*

  • Half Mean Squared Error Loss Functions

func HmseDerivative

func HmseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense

func Huber

func Huber(y_true, y_pred *mat.Dense, params []float64) float64

*

  • Huber Loss Functions
  • Implements a pseudo-huber loss type to approximate
  • Takes in a delta value as a parameter

func HuberDerivative

func HuberDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense

func Linear

func Linear(input *mat.Dense) *mat.Dense

*

  • Linear Activation Funcs

func LinearDeriv

func LinearDeriv(input *mat.Dense) *mat.Dense

func Mae

func Mae(y_true, y_pred *mat.Dense, params []float64) float64

*

  • Mean Absolute Error Loss Functions
  • Derivative defaults to 1 when y_pred = y_true due to not being differentiable

func MaeDerivative

func MaeDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense

func Mse

func Mse(y_true, y_pred *mat.Dense, params []float64) float64

*

  • Mean Squared Error Loss Functions

func MseDerivative

func MseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense

func ReLu

func ReLu(input *mat.Dense) *mat.Dense

*

  • ReLu Activation Funcs
  • Derivative defaults to 0 if x = 0

func ReLuDeriv

func ReLuDeriv(input *mat.Dense) *mat.Dense

func Rmse

func Rmse(y_true, y_pred *mat.Dense, params []float64) float64

*

  • Root Mean Squared Error Loss Functions

func RmseDerivative

func RmseDerivative(y_true, y_pred *mat.Dense, params []float64) *mat.Dense

func Sigmoid

func Sigmoid(input *mat.Dense) *mat.Dense

*

  • Sigmoid Activation Funcs

func SigmoidDeriv

func SigmoidDeriv(input *mat.Dense) *mat.Dense

func Tanh

func Tanh(input *mat.Dense) *mat.Dense

*

  • Tanh Activation Funcs

func TanhDeriv

func TanhDeriv(input *mat.Dense) *mat.Dense

Types

type Activation

type Activation func(input *mat.Dense) *mat.Dense

*

  • Activation Function
  • Defines format of any activation function

type ActivationLayer

type ActivationLayer struct {
	INPUT           *mat.Dense
	OUTPUT          *mat.Dense
	ACTIVATION      Activation
	ACTIVATIONDERIV Activation
}

*

  • ActivationLayer Struct
  • Contains the activation function and its derivative for the layer

func InitActivationLayer

func InitActivationLayer(activation Activation, activationDeriv Activation) *ActivationLayer

*

  • InitActivationLayer()
  • Initializes an activation the activation function and its derivative

func (*ActivationLayer) BackPropagation

func (layer *ActivationLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense

*

  • BackPropagation()
  • Performs back propagation for an activation layer required by Layer interface
  • Returns matrix of error generated from derivative of activation function

func (*ActivationLayer) ForwardPropagation

func (layer *ActivationLayer) ForwardPropagation(input *mat.Dense) *mat.Dense

*

  • ForwardPropagation()
  • Performs forward propagation for an activation layer required by Layer interface
  • Returns output matrix with the function performed

type ConvolutionalLayer

type ConvolutionalLayer struct {
	INPUT  *mat.Dense
	OUTPUT *mat.Dense
}

*

  • ConvolutionalLayer Struct
  • WIP

func InitConvolutionalLayer

func InitConvolutionalLayer(input_size int, output_size int) *ConvolutionalLayer

*

  • InitConvolutionalLayer()
  • WIP

func (*ConvolutionalLayer) BackPropagation

func (layer *ConvolutionalLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense

*

  • BackPropagation()
  • Performs back propagation for a convolutional layer required by Layer interface
  • WIP

func (*ConvolutionalLayer) ForwardPropagation

func (layer *ConvolutionalLayer) ForwardPropagation(input *mat.Dense) *mat.Dense

*

  • ForwardPropagation()
  • Performs forward propagation for a convolutional layer required by Layer interface
  • WIP

type DenseLayer

type DenseLayer struct {
	INPUT   *mat.Dense
	OUTPUT  *mat.Dense
	WEIGHTS *mat.Dense
	BIAS    *mat.Dense
}

*

  • DenseLayer Struct
  • Contains weights and bias for a dense / fully connected layer in a neural network

func InitDenseLayer

func InitDenseLayer(input_size int, output_size int) *DenseLayer

*

  • InitDenseLayer()
  • Initializes a dense layer given input and output shape

func (*DenseLayer) BackPropagation

func (layer *DenseLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense

*

  • BackPropagation()
  • Performs back propagation for a dense layer required by Layer interface
  • Returns matrix of the input error from the current layer

func (*DenseLayer) ForwardPropagation

func (layer *DenseLayer) ForwardPropagation(input *mat.Dense) *mat.Dense

*

  • ForwardPropagation()
  • Performs forward propagation for a dense layer required by Layer interface
  • Returns dot product of input and weights plus the bias

type FlattenLayer

type FlattenLayer struct {
	INPUT        *mat.Dense
	OUTPUT       *mat.Dense
	INPUT_SHAPE  int
	OUTPUT_SHAPE int
}

*

  • FlattenLayer Struct
  • Contains input and output matrices

func InitFlattenLayer

func InitFlattenLayer(input_size int, output_size int) *FlattenLayer

*

  • InitFlattenLayer()
  • Flattened layer serves to simply reshape inputs and outputs

func (*FlattenLayer) BackPropagation

func (layer *FlattenLayer) BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense

*

  • BackPropagation()
  • Performs back propagation for a flat layer required by Layer interface
  • WIP for Convolutional Layer

func (*FlattenLayer) ForwardPropagation

func (layer *FlattenLayer) ForwardPropagation(input *mat.Dense) *mat.Dense

*

  • ForwardPropagation()
  • Performs forward propagation for a flat layer required by Layer interface
  • WIP for Convolutional Layer

func (*FlattenLayer) GetShape

func (layer *FlattenLayer) GetShape() (int, int)

*

  • GetShape()
  • Accessor for flat layer shape

type Layer

type Layer interface {
	ForwardPropagation(input *mat.Dense) *mat.Dense
	BackPropagation(output_error *mat.Dense, learning_rate float64) *mat.Dense
}

*

  • Layer Interface
  • Defines required functions for any layer

type Network

type Network struct {
	LAYERS      []*Layer
	LOSSFUNC    func(y_true, y_pred *mat.Dense, params []float64) float64
	LOSSDERIV   func(y_true, y_pred *mat.Dense, params []float64) *mat.Dense
	LOSSPARAMS  []float64
	OUTPUT_SIZE int
	LAYER_COUNT int
}

*

  • Network Struct
  • Contains neural network specifics and helper functions
  • Defines layers and loss functions

func (*Network) AddLayer

func (net *Network) AddLayer(layerType, activationType string, output_nodes int)

*

  • AddLayer()
  • Adds specific layer to neural network given activation type and input/output neuron dimensions

func (*Network) Fit

func (net *Network) Fit(x_train, y_train [][]float64, epochs int, learning_rate float64, debug bool)

*

  • Fit()
  • Fit the neural network given training data, number of epochs, and a learning rate
  • Debug option provided for printing data from each epoch

func (*Network) Predict

func (net *Network) Predict(input [][]float64) [][]float64

*

  • Predict()
  • Given sample data, return predicted values ran through the neural network

func (*Network) SetLoss

func (net *Network) SetLoss(lossType string, params []float64)

*

  • SetLoss()
  • Contains neural network specifics and helper functions
  • Defines layers and loss functions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL