multilayer

package
v0.0.0-...-bed4406 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiLayerPerceptron

type MultiLayerPerceptron struct {
	HiddenLayers []layer.Layer

	Reader string
	// contains filtered or unexported fields
}

MultiLayerPerceptron is an abstraction of the HiddenLayers and outputLayer. It performs the forward propagation sequentially layer by layer for each epoch, but concurrently for all vectors in the expected batch size.

func New

func New(HiddenLayers []int,
	outputLayer int,
	hiddenActFn,
	outputActFn string,
	batchSize,
	epochSize int,
	learningRate float64,
	reader string) (MultiLayerPerceptron, error)

New instantiates a Fully Connected Neural Network or MultiLayerPerceptron. It receives a slice of in/out sizes for each hidden layer and an out size for the output layer. So ([1, 2, 3], 4) would mean 2 hidden layers and 1 in/output with the respective sizes: 1->2, 2->3, 3->4. New also receives the activation functions for the hidden and output layers as well as a batch, epoch size and a learning rate.

func (*MultiLayerPerceptron) BackProp

func (m *MultiLayerPerceptron) BackProp(output matrix.Matrix) error

BackProp receives an expected output Y, calculates the first delta using the quadratic function (might generalize later). It then propagates the error further saving the weight and bias errors indexing in the member attributes for later use with the Gradient Descent.

func (*MultiLayerPerceptron) Equal

Equal compares two mlps by testing each of the hiddenlayers with the correct indices, the output ones and the batch, epoch und learning rate values. The remaining member attributes are only placeholders for the back propagation and radient descent algorithm, no prevent unneccessary memory allocation so don't need to be exactly the same.

func (*MultiLayerPerceptron) ForwProp

func (m *MultiLayerPerceptron) ForwProp(in matrix.Matrix) (matrix.Matrix, error)

ForwProp calls the ForwProp method for each layer sequentially saving its output in the in vector each time. It returns an output vector which gets compared with the expected value.

func (*MultiLayerPerceptron) GradientDescent

func (m *MultiLayerPerceptron) GradientDescent() error

GradientDescent is called after calculating the errors for both the bias and weights in each layer. It then sequentially updates both. It does so calling the method in each layer which simply subtracts the multiplyed error and learning rate from the current value.

func (*MultiLayerPerceptron) MarshalBinary

func (m *MultiLayerPerceptron) MarshalBinary() ([]byte, error)

MarshalBinary is the method needed to implement the BinaryMarshaler in the encoding package. It will be called to parse the mlp data into binary form to be saved in a file for later use.

func (*MultiLayerPerceptron) String

func (m *MultiLayerPerceptron) String() (s string)

func (*MultiLayerPerceptron) UnmarshalBinary

func (m *MultiLayerPerceptron) UnmarshalBinary(data []byte) error

UnmarshalBinary is the method needed to implement the BinaryUnmarshaler in the encoding package. It will be called to parse a gob file and assign the data to and instance of an mlp.

Jump to

Keyboard shortcuts

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