Documentation
¶
Index ¶
- type Adam
- type Layer
- type Network
- func (n *Network) Add(other *Network)
- func (n *Network) Clone(newName string) (clone *Network)
- func (n *Network) Divide(scalar float64)
- func (n *Network) GetCost() float64
- func (n *Network) GetName() string
- func (n *Network) GetNames() (inputNames, outputNames []string)
- func (n *Network) Learn(inputs []float64, targets []float64, learningRate float64) (cost float64)
- func (n *Network) LearnNamed(inputMap, targetMap map[string]float64, rate float64) (cost float64)
- func (n *Network) Mimic(oldNet *Network, trainingSet *TrainingSet, learningRate float64, ...) (cost float64, err error)
- func (n *Network) MkTrainingSet(trainingSet *TrainingSet) (newSet *TrainingSet)
- func (n *Network) Predict(inputs []float64) (outputs []float64)
- func (n *Network) PredictNamed(inputMap map[string]float64) (outputMap map[string]float64)
- func (n *Network) Randomize()
- func (n *Network) Save() (out string)
- func (n *Network) SetActivation(layerNum, nodeNum int, activation string)
- func (n *Network) SetInputNames(names ...string)
- func (n *Network) SetOutputNames(names ...string)
- func (n *Network) Train(trainingSet *TrainingSet, learningRate float64, iterations int, ...) (cost float64, err error)
- func (n *Network) Validate(ts *TrainingSet, maxCost float64) (err error)
- func (n *Network) Zero()
- type Node
- type SimpleNode
- type TrainingCase
- type TrainingSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adam ¶
type Adam struct {
// contains filtered or unexported fields
}
Adam is an adaptive learning rate algorithm for gradient descent. See https://arxiv.org/pdf/1412.6980.pdf
type Layer ¶
type Layer struct {
Nodes []*SimpleNode
// contains filtered or unexported fields
}
Layer represents a layer of nodes.
func (*Layer) InputGradients ¶
InputGradients returns the gradients for the inputs of the given layer.
type Network ¶
type Network struct {
Name string
InputCount int
InputNames []string
OutputNames []string
Layers []*Layer
// contains filtered or unexported fields
}
Network represents a neural network
func NewNetwork ¶
NewNetwork creates a new network with the given configuration. The layerSizes arg is a slice of integers, where each integer is the number of nodes in a layer. The activation function defaults to sigmoid, and the default can be overriden for any layer or node by calling SetActivation().
func (*Network) Add ¶
Add adds the weights and biases of the given network to this network. The given network must have the same structure as this network.
func (*Network) Learn ¶
Learn runs one backpropagation iteration through the network. It takes inputs and targets and returns the total cost of the output nodes.
func (*Network) LearnNamed ¶
LearnNamed trains the network for one iteration with the given named input and target maps. It ignores named inputs and targets which are not in the network, and assumes zero values for named inputs and targets which are in the network but not in the given maps.
func (*Network) Mimic ¶
func (n *Network) Mimic(oldNet *Network, trainingSet *TrainingSet, learningRate float64, iterations int, maxCost float64) (cost float64, err error)
Mimic trains the network to match the outputs of oldNet given trainingSet inputs. Ignores the target values in trainingSet; instead asks oldNet to predict output values for trainingSet inputs, then uses those output values as targets for training the network.
func (*Network) MkTrainingSet ¶
func (n *Network) MkTrainingSet(trainingSet *TrainingSet) (newSet *TrainingSet)
MkTrainingSet creates a new training set by running the given inputs through the network. The targets in the input training set are ignored.
func (*Network) Predict ¶
Predict executes the forward function of a network and returns its output values.
func (*Network) PredictNamed ¶
PredictNamed returns named outputs for the given named inputs. It ignores named inputs which are not in the network, and sets to zero named inputs which are in the network but not in the given map.
func (*Network) Randomize ¶
func (n *Network) Randomize()
RandomizeWeights sets the weights of all nodes to random values
func (*Network) Save ¶
Save serializes the network configuration, weights, and biases to a JSON string.
func (*Network) SetActivation ¶
SetActivation sets the activation function for the given layer and node. The layerNum and nodeNum args are 0-based. If the layerNum is -1, then the activation function is set for all layers. If the nodeNum is -1, then the activation function is set for all nodes in the given layer. The activation function can be one of "sigmoid", "tanh", "relu", or "linear".
func (*Network) SetInputNames ¶
SetInputNames sets the names of the inputs. The names are used in the arguments to LearnNamed() and PredictNamed().
func (*Network) SetOutputNames ¶
SetOutputNames sets the names of the outputs. The names are used in the arguments to LearnNamed() and PredictNamed().
func (*Network) Train ¶
func (n *Network) Train(trainingSet *TrainingSet, learningRate float64, iterations int, maxCost float64) (cost float64, err error)
Train the network given a training set.
type SimpleNode ¶
type SimpleNode struct {
Weights []float64 // weights for the inputs of this node
Bias float64 // bias for this node
ActivationName string // name of the activation function
// contains filtered or unexported fields
}
SimpleNode represents a node in a neural network.
func (*SimpleNode) Activation ¶
func (n *SimpleNode) Activation(x float64) float64
Activation runs the activation function of this node.
func (*SimpleNode) ActivationD1 ¶
func (n *SimpleNode) ActivationD1(x float64) float64
ActivationD1 runs the derivative of the activation function of this node.
func (*SimpleNode) AddInputGradients ¶
func (n *SimpleNode) AddInputGradients(outputGradient float64, inputGradients []float64)
AddInputGradients adds the gradients for the inputs of this node to the given gradient vector.
func (*SimpleNode) Output ¶
func (n *SimpleNode) Output() (output float64)
Output executes the forward function of a node and returns its output value.
type TrainingCase ¶
TrainingCase represents a single training case.
func NewTrainingCase ¶
func NewTrainingCase(inputs, targets []float64) (c *TrainingCase)
NewTrainingCase creates a new training case.
type TrainingSet ¶
type TrainingSet struct {
Cases []*TrainingCase
}
TrainingSet represents a set of training cases.
func NewTrainingSet ¶
func NewTrainingSet() (ts *TrainingSet)
NewTrainingSet creates a new training set.
func (*TrainingSet) Add ¶
func (ts *TrainingSet) Add(inputs, targets []float64)
Add adds a training case to the set.
func (*TrainingSet) Append ¶
func (ts *TrainingSet) Append(other *TrainingSet) (newSet *TrainingSet)
Append appends the given training set to the current training set, returning a new training set.