Documentation ¶
Overview ¶
Example ¶
rand.Seed(1338) PrintCalculation = false n := CreatePerceptron(2, 3, 1) dataset := Dataset{ {Vector{0.0, 0.0}, Vector{1.0}}, {Vector{1.0, 0.0}, Vector{0.0}}, {Vector{0.0, 1.0}, Vector{0.0}}, {Vector{1.0, 1.0}, Vector{1.0}}, } trainer := PerceptronTrainer{&n, dataset} trainer.BackPropagation(10000) PrintCalculation = true n.Calculate(Vector{0.0, 0.0}) n.Calculate(Vector{1.0, 0.0}) n.Calculate(Vector{0.0, 1.0}) n.Calculate(Vector{1.0, 1.0})
Output: Input: [0 0] Output: [0.9816677167418877] Input: [1 0] Output: [0.020765305091063144] Input: [0 1] Output: [0.01825325088702373] Input: [1 1] Output: [0.9847884089930483]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ACTIVATION neuronFunction = func(x float64) float64 { return 1 / (1 + math.Exp(-x)) }
ACTIVATION store default activation function.
var DEACTIVATION neuronFunction = func(x float64) float64 { var fx = ACTIVATION(x) return fx * (1 - fx) }
DEACTIVATION store default deactivation function.
var PrintCalculation = false
PrintCalculation logs all calculate calls (print input and output).
Functions ¶
func ConnectNeurons ¶
ConnectNeurons connect two neurons. It creates synapse and add connection to input and output Neuron.
func ToJSON ¶
func ToJSON(network Perceptron) string
ToJSON dump and transform Perceptron to json string.
Types ¶
type CoreNeuron ¶
type CoreNeuron struct {
// contains filtered or unexported fields
}
CoreNeuron - entity with float64 weight (it is bias) and connection. Activation result store in cache for training.
type Neuron ¶
type Neuron interface {
// contains filtered or unexported methods
}
Neuron - interface for all Neuron. Each Neuron must have: - coreNeuron is a basic neuron for all types - getCore() is a the function for getting pointer to CoreNeuron - live() - method for running neuron's goroutine. All kind of Neurons implement functionality live - changeWeight is the method for training
type Perceptron ¶
type Perceptron struct {
// contains filtered or unexported fields
}
Perceptron implement Neural Network Perceptron by collect layers with Neurons and input/output channels.
func CreatePerceptron ¶
func CreatePerceptron(layers ...int) Perceptron
CreatePerceptron make new Perceptron NN with count of neurons in each Layer.
func FromJSON ¶
func FromJSON(jsonString string) Perceptron
FromJSON load json string and create Perceptron.
func (*Perceptron) Calculate ¶
func (n *Perceptron) Calculate(input Vector) Vector
Calculate run Network calculations by broadcasting signals to input channels and wait signals from output array of chan.
func (*Perceptron) ConnectLayers ¶
func (n *Perceptron) ConnectLayers()
ConnectLayers create all to all connection between layers.
func (*Perceptron) RunNeurons ¶
func (n *Perceptron) RunNeurons()
RunNeurons create goroutines for all Neuron in Perceptron.
type PerceptronTrainer ¶
type PerceptronTrainer struct { Network *Perceptron Dataset Dataset }
PerceptronTrainer is a trainer for Perceptron networks
func (*PerceptronTrainer) BackPropagation ¶
func (t *PerceptronTrainer) BackPropagation(times int)
BackPropagation train Network input Dataset for 'times' times.