nngo

package
v0.0.0-...-f80d65e Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActivationSigmoid = 0
	ActivationRelu    = 1
	ActivationTanh    = 2
)

Each constant represents an activation function and its derivative This makes the definition of neural networks easier

View Source
const (
	LossMse = 0
	LossMae = 1
)

Each constant represents an loss function and its derivative This makes the definition of neural networks easier

Variables

This section is empty.

Functions

func GetColVector

func GetColVector(matrix mat.Dense, index int) mat.VecDense

return the column as a vector instead of an slice

func GetMaxIndex

func GetMaxIndex(vector mat.VecDense) int

returns the index of the element with the max value

func Mae

func Mae(yTrue, yPred mat.VecDense) (float64, error)

func MaeDerivative

func MaeDerivative(yTrue, yPred mat.VecDense) (mat.VecDense, error)

func Mse

func Mse(yTrue, yPred mat.VecDense) (float64, error)

func MseDerivative

func MseDerivative(yTrue, yPred mat.VecDense) (mat.VecDense, error)

func Relu

func Relu(x float64) float64

func ReluDerivative

func ReluDerivative(x float64) float64

func Sigmoid

func Sigmoid(x float64) float64

func SigmoidDerivative

func SigmoidDerivative(x float64) float64

func Tanh

func Tanh(x float64) float64

func TanhDerivative

func TanhDerivative(x float64) float64

Types

type Activation

type Activation struct {
	// contains filtered or unexported fields
}

consists of a base layer and an activation function this layer just applies the activation function to the output of a dense layer

func NewActivation

func NewActivation(size, activationSpecs int) (*Activation, error)

constructor for Activation layer

creates a new activation layer with random values for the input and output with the given data

inputSize and outputSize need to be positive

type Base

type Base struct {
	// contains filtered or unexported fields
}

basic layer which consists of input and output vector

type Dense

type Dense struct {
	// contains filtered or unexported fields
}

Dense layer consists of a base layer with a weight matrix, bias vector

func NewDense

func NewDense(inputSize, outputSize int) (*Dense, error)

constructor for DenseLayer

creates a new dense layer with random values for the vectors and matrices with the given data

inputSize and outputSize need to be positive

type Layer

type Layer interface {
	// contains filtered or unexported methods
}

default methods that have to be implemented by each layer

a layer needs an forward and backward propagation method

type Network

type Network struct {
	// contains filtered or unexported fields
}

specifies a neural network layers are saved inside a slice this structure allows for almost every possible neural network configuration

func NewNetwork

func NewNetwork(layerSpecs [][]int, lossSpecs int) (*Network, error)

create a neural network each layer is specified by a subslice e.g. {4, 5, 0} specifies a layer with 4 input, 5 output neurons and Sigmoid as a activation function

func (*Network) EvaluateOneHot

func (dense *Network) EvaluateOneHot(test *Set) float64

this evaluate function only works for one hot encoded input

func (*Network) Predict

func (dense *Network) Predict(input mat.VecDense) mat.VecDense

func (*Network) Train

func (dense *Network) Train(train *Set, epochs int, learningRate float64) error

type Set

type Set struct {
	Data   mat.Dense
	Labels mat.Dense
}

saves all the data and labels

the used data consists of float vectors this achieves maximum flexibility users can use one hot encoding, one dimensional vectors and n-dimensional vectors

each index of the data corresponds to the same label index in the labels data labels are saved as vectors for easier access during the training process labels row size should match the output size of the output layer

you can read the complete dataset and then later convert it into splitSet with splitDataSet()

func NewSet

func NewSet(data, labels [][]float64) (*Set, error)

converts data vectors into a matrix each subslice of the data slice should represent a vector the size of each label vector should match the output size of the output layer

type SplitSet

type SplitSet struct {
	Train Set
	Test  Set
}

saves train and test data into struct

func NewSplitSet

func NewSplitSet(testData, trainData, testLabels, trainLabels [][]float64) (*SplitSet, error)

converts data vectors into a matrix each subslice of the data slice should represent a vector the size of each label vector should match the output size of the output layer

func NewSplitSetAlt

func NewSplitSetAlt(data, labels [][]float64, splitRatio float64) (*SplitSet, error)

converts data vectors into a matrix each subslice of the data slice should represent a vector the size of each label vector should match the output size of the output layer

Jump to

Keyboard shortcuts

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