goneural

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

README

goneural

Golang neural networking

Development package

This is a development package and currently only supports dense layers. There is also currently no way to train the networks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLayerTotLoss

func GetLayerTotLoss(l LossFunction, expectedX, predictedX *Matrix) float64

func ShuffleBoth

func ShuffleBoth(X, Y []*Matrix)

Types

type Activation

type Activation interface {
	// Calc : Calculate the activation for x
	Calc(x float64) float64
	// Diff : Calculate the differential of the activation for x
	Diff(x float64) float64
}

Activation : An interface type that denotes an activations function.

type DenseLayer

type DenseLayer struct {
	Weights Matrix
	Ac      Activation
	// contains filtered or unexported fields
}

DenseLayer : The standard type of dense neural network layer

func NewDenseLayer

func NewDenseLayer(numInputs, numOutputs int, activation Activation) *DenseLayer

func (*DenseLayer) GetActivation

func (l *DenseLayer) GetActivation() Activation

func (*DenseLayer) GetNumInputs

func (l *DenseLayer) GetNumInputs() int

func (*DenseLayer) GetNumOutputs

func (l *DenseLayer) GetNumOutputs() int

func (*DenseLayer) PropagateValues

func (l *DenseLayer) PropagateValues(X *Matrix) *Matrix

func (*DenseLayer) TrainGradientDescent

func (l *DenseLayer) TrainGradientDescent(learningRate float64, layerInputs, deltas *Matrix) *Matrix

TrainGradientDescent : DEPRECATED

func (*DenseLayer) TrainMinibatch

func (l *DenseLayer) TrainMinibatch(learningRate float64, avInputs, avDeltas *Matrix) *Matrix

type FeedForwardNetwork

type FeedForwardNetwork struct {
	Inputs  int
	Outputs int
	Layers  []Layer
	Loss    LossFunction
}

func NewFeedForwardNetwork

func NewFeedForwardNetwork(inputs int, loss LossFunction) *FeedForwardNetwork

func (*FeedForwardNetwork) AddLayer

func (n *FeedForwardNetwork) AddLayer(layer Layer)

func (*FeedForwardNetwork) GetLastLayerDeltas

func (n *FeedForwardNetwork) GetLastLayerDeltas(pred, expec *Matrix) *Matrix

func (*FeedForwardNetwork) Predict

func (n *FeedForwardNetwork) Predict(X *Matrix) *Matrix

func (*FeedForwardNetwork) PredictAll

func (n *FeedForwardNetwork) PredictAll(Xs []*Matrix) []*Matrix

type Layer

type Layer interface {
	// PropagateValues : Propagates an input matrix though the layer and returns the calculated matrix
	PropagateValues(X *Matrix) *Matrix
	// GetNumInputs : Gets the number of inputs
	GetNumInputs() int
	// GetNumOutputs : Gets the number of outputs
	GetNumOutputs() int
	// GetActivation : Gets the activation function of this layer
	GetActivation() Activation
}

Layer : A interface type that describes layer in a feed forward network

type LeakyReLUActivation

type LeakyReLUActivation struct {
	// SubZeroGradient : The gradient of the function when x < 0
	SubZeroGradient float64
}

LeakyReLUActivation : A leaky ReLU activation

func (LeakyReLUActivation) Calc

func (LeakyReLUActivation) Diff

type LinearActivation

type LinearActivation types.Nil

LinearActivation : Activation where y=x

func (LinearActivation) Calc

func (a LinearActivation) Calc(x float64) float64

func (LinearActivation) Diff

func (a LinearActivation) Diff(x float64) float64

type LossFunction

type LossFunction interface {
	SingleLoss(expected, predicted float64) float64
	SingleLossDiff(expected, predicted float64) float64
}

type Matrix

type Matrix struct {
	Shape  []int
	Values []float64
}

func GetLayerLossDiffs

func GetLayerLossDiffs(l LossFunction, expectedX, predictedX *Matrix) *Matrix

func New1DMatrix

func New1DMatrix(vals []float64) *Matrix

func New2DMatrix

func New2DMatrix(vals [][]float64) *Matrix

func NewZerosMatrix

func NewZerosMatrix(shape ...int) *Matrix

func (*Matrix) Add

func (m *Matrix) Add(m2 *Matrix) *Matrix

func (*Matrix) AddValue1D

func (m *Matrix) AddValue1D(i int, v float64)

func (*Matrix) AddValue2D

func (m *Matrix) AddValue2D(x, y int, v float64)

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

func (*Matrix) CopyTo

func (m *Matrix) CopyTo(m2 *Matrix)

func (*Matrix) CopyToSmaller

func (m *Matrix) CopyToSmaller(m2 *Matrix)

func (*Matrix) Get1DLength

func (m *Matrix) Get1DLength() int

func (*Matrix) GetValue1D

func (m *Matrix) GetValue1D(i int) float64

func (*Matrix) GetValue2D

func (m *Matrix) GetValue2D(x, y int) float64

func (*Matrix) Mul

func (m *Matrix) Mul(f float64) *Matrix

func (*Matrix) SetValue1D

func (m *Matrix) SetValue1D(i int, v float64)

func (*Matrix) SetValue2D

func (m *Matrix) SetValue2D(x, y int, v float64)

type MinibatchOptimizer

type MinibatchOptimizer struct {
	LearningRate float64
	BatchSize    int
}

func (*MinibatchOptimizer) FitBatch

func (o *MinibatchOptimizer) FitBatch(n *FeedForwardNetwork, X, Y []*Matrix)

func (*MinibatchOptimizer) GetBatchSize

func (o *MinibatchOptimizer) GetBatchSize() int

type Optimizer

type Optimizer interface {
	FitBatch(n *FeedForwardNetwork, X, Y []*Matrix)
	GetBatchSize() int
}

type ReLUActivation

type ReLUActivation types.Nil

ReLUActivation : An activation for ReLU

func (ReLUActivation) Calc

func (a ReLUActivation) Calc(x float64) float64

func (ReLUActivation) Diff

func (a ReLUActivation) Diff(x float64) float64

type SGDLayer

type SGDLayer interface {
	Layer
	TrainMinibatch(learningRate float64, layerInputs, totDeltas *Matrix) *Matrix
}

type SerialTrainer

type SerialTrainer struct {
	Opt                     Optimizer
	UseRelativeLearningRate bool
}

func (*SerialTrainer) Fit

func (s *SerialTrainer) Fit(n *FeedForwardNetwork, Xs, Ys []*Matrix, epochs, printRate int)

type SigmoidActivation

type SigmoidActivation types.Nil

SigmoidActivation : A sigmoid activation

func (SigmoidActivation) Calc

func (a SigmoidActivation) Calc(x float64) float64

func (SigmoidActivation) Diff

func (a SigmoidActivation) Diff(x float64) float64

type SquaredErrorLoss

type SquaredErrorLoss types.Nil

func (SquaredErrorLoss) SingleLoss

func (l SquaredErrorLoss) SingleLoss(expected, predicted float64) float64

func (SquaredErrorLoss) SingleLossDiff

func (l SquaredErrorLoss) SingleLossDiff(expected, predicted float64) float64

Jump to

Keyboard shortcuts

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