network

package
v0.0.0-...-c4bfc47 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Columns

func Columns(matrix Matrix) int

Columns returns number of matrix's columns

func ErrorNotSameSize

func ErrorNotSameSize(matrix, matrix2 Matrix)

ErrorNotSameSize panics if the matrices do not have the same dimension

func MultipliesByTwo

func MultipliesByTwo(x float64) float64

MultipliesByTwo takes a float and returns the float multiplied by two

func Rows

func Rows(matrix Matrix) int

Rows returns number of matrix's rows

func Sigmoid

func Sigmoid(x float64) float64

Sigmoid is the activation function

func SubtractsOne

func SubtractsOne(x float64) float64

SubtractsOne takes a float and returns the float subtracted by one

Types

type Derivative

type Derivative struct {
	Delta      Matrix
	Adjustment Matrix
}

Derivative contains the derivatives of `z` and the adjustments

type Matrix

type Matrix [][]float64

Matrix is an alias for [][]float64

func ApplyFunction

func ApplyFunction(matrix Matrix, fn func(x float64) float64) Matrix

ApplyFunction returns a matrix where fn has been applied

func ApplyFunctionWithIndex

func ApplyFunctionWithIndex(matrix Matrix, fn func(i, j int, x float64) float64) Matrix

ApplyFunctionWithIndex returns a matrix where fn has been applied with the indexes provided

func ApplyRate

func ApplyRate(matrix Matrix, rate float64) Matrix

ApplyRate returns a matrix where the learning rate has been multiplies

func CreateMatrix

func CreateMatrix(rows, columns int) (matrix Matrix)

CreateMatrix returns an empty matrix which is the size of rows and columns

func Difference

func Difference(matrix, matrix2 Matrix) (resultMatrix Matrix)

Difference returns the difference between matrix and matrix2

func DotProduct

func DotProduct(matrix, matrix2 Matrix) Matrix

DotProduct returns a matrix which is the result of the dot product between matrix and matrix2

func Multiplication

func Multiplication(matrix, matrix2 Matrix) (resultMatrix Matrix)

Multiplication returns the multiplication of matrix and matrix2

func RandomMatrix

func RandomMatrix(rows, columns int) (matrix Matrix)

RandomMatrix returns the value of a random matrix of *rows* and *columns* dimensions and where the values are between *lower* and *upper*.

func Sum

func Sum(matrix, matrix2 Matrix) (resultMatrix Matrix)

Sum returns the sum of matrix and matrix2

func Transpose

func Transpose(matrix Matrix) (resultMatrix Matrix)

Transpose returns the matrix transposed

type Network

type Network struct {
	Layers  []Matrix
	Weights []Matrix
	Biases  []Matrix
	Output  Matrix
	Rate    float64
	Errors  []float64
	Time    float64
	Locale  string
}

Network contains the Layers, Weights, Biases of a neural network then the actual output values and the learning rate.

func CreateNetwork

func CreateNetwork(locale string, rate float64, input, output Matrix, hiddensNodes ...int) Network

CreateNetwork creates the network by generating the layers, weights and biases

func LoadNetwork

func LoadNetwork(fileName string) *Network

LoadNetwork returns a Network from a specified file

func (Network) Adjust

func (network Network) Adjust(derivatives []Derivative)

Adjust make the adjusts

func (Network) ComputeDerivatives

func (network Network) ComputeDerivatives(i int, derivatives []Derivative) Derivative

ComputeDerivatives returns the derivatives of a specific layer l defined by i

func (*Network) ComputeError

func (network *Network) ComputeError() float64

ComputeError returns the average of all the errors after the training

func (Network) ComputeLastLayerDerivatives

func (network Network) ComputeLastLayerDerivatives() Derivative

ComputeLastLayerDerivatives returns the derivatives of the last layer L

func (*Network) FeedBackward

func (network *Network) FeedBackward()

FeedBackward executes back propagation to adjust the weights for all the layers

func (*Network) FeedForward

func (network *Network) FeedForward()

FeedForward executes forward propagation for the given inputs in the network

func (*Network) Predict

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

Predict returns the predicted value for a training example

func (Network) Save

func (network Network) Save(fileName string)

Save saves the neural network in a specified file which can be retrieved with LoadNetwork

func (*Network) Train

func (network *Network) Train(iterations int)

Train trains the neural network with a given number of iterations by executing forward and back propagation

Jump to

Keyboard shortcuts

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