Documentation ¶
Index ¶
- func ValidateTrainConfig(c *config.TrainConfig) error
- type ActivFunc
- type Cost
- type CrossEntropy
- type Layer
- func (l Layer) ActFn() func(int, int, float64) float64
- func (l Layer) ActGrad() func(int, int, float64) float64
- func (l *Layer) Deltas() *mat64.Dense
- func (l *Layer) FwdOut(inputMx mat64.Matrix) (mat64.Matrix, error)
- func (l Layer) ID() string
- func (l Layer) Kind() LayerKind
- func (l *Layer) SetWeights(w *mat64.Dense) error
- func (l *Layer) Weights() *mat64.Dense
- type LayerKind
- type LogLikelihood
- type Network
- func (n *Network) AddLayer(layer *Layer) error
- func (n *Network) BackProp(inMx, errMx mat64.Matrix, fromLayer int) error
- func (n *Network) Classify(inMx mat64.Matrix) (mat64.Matrix, error)
- func (n *Network) ForwardProp(inMx mat64.Matrix, toLayer int) (mat64.Matrix, error)
- func (n Network) ID() string
- func (n Network) Kind() NetworkKind
- func (n Network) Layers() []*Layer
- func (n *Network) Train(c *config.TrainConfig, inMx *mat64.Dense, labelsVec *mat64.Vector) error
- func (n *Network) Validate(valInMx *mat64.Dense, valOut *mat64.Vector) (float64, error)
- type NetworkKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateTrainConfig ¶
func ValidateTrainConfig(c *config.TrainConfig) error
ValidateTrainConfig validates training configuration. It returns error if any of the supplied configuration parameters are invalid.
Types ¶
type Cost ¶
type Cost interface { // CostFunc defines neural network cost function for given input, output and labels. // It returns a single number: cost for given input and output CostFunc(mat64.Matrix, mat64.Matrix, mat64.Matrix) float64 // Delta implements function that calculates error in the last network layer // It returns the output error matrix Delta(mat64.Matrix, mat64.Matrix) mat64.Matrix }
Cost is neural network training cost
type CrossEntropy ¶
type CrossEntropy struct{}
CrossEntropy implements Cost interface
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer represents a Neural Network layer.
func NewLayer ¶
func NewLayer(c *config.LayerConfig, layerIn int) (*Layer, error)
NewLayer creates a new neural network layer and returns it. Layer weights are initialized to uniformly distributed random values (-1,1) NewLayer fails with error if the neural network supplied as a parameter does not exist.
func (*Layer) Deltas ¶
Deltas returns layer's output deltas matrix Deltas matrix is initialized to zeros and is only non-zero if the back propagation algorithm has been run.
func (*Layer) FwdOut ¶
FwdOut calculates forward output of the network layer for given input. If the layer is an INPUT layer, it returns the matrix supplied as an argument.
func (*Layer) SetWeights ¶
SetWeights allows to set neural network layer weights. It fails with error if either the supplied weights have different dimensions than the existing layer weights or if the passed in weights matrix is nil or if the layer is an INPUT layer: INPUT layer has no weights matrix.
type LayerKind ¶
type LayerKind uint
LayerKind defines type of neural network layer There are three kinds available: INPUT, HIDDEN and OUTPUT
type LogLikelihood ¶
type LogLikelihood struct{}
LogLikelihood implements Cost interface
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network represents Neural Network
func NewNetwork ¶
NewNetwork creates new Neural Network based on the passed in configuration parameters. It fails with error if either the requested network type is not supported or if any of the neural network layers failed to be created.
func (*Network) AddLayer ¶
AddLayer adds a neural layer to neural network or fails with error AddLayer places restrictions on adding new layers to the network: 1. INPUT layer - there can only be one INPUT layer 2. HIDDEN layer - new HIDDEN layer is appened after the last HIDDEN layer 3. OUTPUT layer - there can only be one OUTPUT layer AddLayer fails with error if either 1. or 3. are not satisfied
func (*Network) BackProp ¶
BackProp performs back propagation of neural network. It traverses neural network recursively from layer specified via parameter and calculates error deltas for each network layer. It fails with error if either the supplied input and delta matrices are nil or if the specified from boundary goes beyond the first network layer that can have output errors calculated
func (*Network) Classify ¶
Classify classifies the provided data vector to a particular label class. It returns a matrix that contains probabilities of the input belonging to a particular class It returns error if the network forward propagation fails at any point during classification.
func (*Network) ForwardProp ¶
ForwardProp performs forward propagation for a given input up to a specified network layer. It recursively activates all layers in the network and returns the output in a matrix It fails with error if requested end layer index is beyond all available layers or if the supplied input data is nil.
type NetworkKind ¶
type NetworkKind uint
NetworkKind defines a type of neural network
const ( // FEEDFWD is a feed forward Neural Network FEEDFWD NetworkKind = iota + 1 )
func (NetworkKind) String ¶
func (n NetworkKind) String() string
String implements Stringer interface for pretty printing