tanis

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: GPL-3.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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

func NewAdam

func NewAdam(learningRate, beta1, beta2 float64, nWeights int) *Adam

NewAdam returns a new Adam optimizer

func (*Adam) Update

func (a *Adam) Update(l *Layer, outputGradients []float64)

Update updates the weights of the given layer using Adam

type Layer

type Layer struct {
	Nodes []*SimpleNode
	// contains filtered or unexported fields
}

Layer represents a layer of nodes.

func (*Layer) InputGradients

func (l *Layer) InputGradients(outputGradients []float64) (inputGradients []float64)

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 Load

func Load(txt string) (n *Network, err error)

Load deserializes a network configuration, weights, and biases from a JSON string.

func NewNetwork

func NewNetwork(name string, inputCount int, layerSizes ...int) (net *Network)

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

func (n *Network) Add(other *Network)

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) Clone

func (n *Network) Clone(newName string) (clone *Network)

Clone returns a deep copy of the network, giving it a new name.

func (*Network) Divide

func (n *Network) Divide(scalar float64)

Divide divides the weights and biases of this network by the given scalar.

func (*Network) GetCost

func (n *Network) GetCost() float64

GetCost returns the cost of the most recent call to Train() or Learn().

func (*Network) GetName

func (n *Network) GetName() string

GetName returns the name of the network.

func (*Network) GetNames

func (n *Network) GetNames() (inputNames, outputNames []string)

GetNames returns the names of the inputs and outputs.

func (*Network) Learn

func (n *Network) Learn(inputs []float64, targets []float64, learningRate float64) (cost float64)

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

func (n *Network) LearnNamed(inputMap, targetMap map[string]float64, rate float64) (cost float64)

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

func (n *Network) Predict(inputs []float64) (outputs []float64)

Predict executes the forward function of a network and returns its output values.

func (*Network) PredictNamed

func (n *Network) PredictNamed(inputMap map[string]float64) (outputMap map[string]float64)

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

func (n *Network) Save() (out string)

Save serializes the network configuration, weights, and biases to a JSON string.

func (*Network) SetActivation

func (n *Network) SetActivation(layerNum, nodeNum int, activation string)

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

func (n *Network) SetInputNames(names ...string)

SetInputNames sets the names of the inputs. The names are used in the arguments to LearnNamed() and PredictNamed().

func (*Network) SetOutputNames

func (n *Network) SetOutputNames(names ...string)

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.

func (*Network) Validate

func (n *Network) Validate(ts *TrainingSet, maxCost float64) (err error)

Validate validates a network against a training set, ensuring that the network outputs are within maxCost of the expected outputs.

func (*Network) Zero

func (n *Network) Zero()

Zero initializes the weights and biases to zero.

type Node

type Node interface {
}

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

type TrainingCase struct {
	Inputs  []float64
	Targets []float64
}

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.

Jump to

Keyboard shortcuts

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