Varis: github.com/Xamber/Varis Index | Examples | Files

package varis

import "github.com/Xamber/Varis"

Code:

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

Package Files

dumps.go neuron.go perceptron.go synapse.go train.go varis.go vector.go

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

func ConnectNeurons Uses

func ConnectNeurons(in Neuron, out Neuron, weight float64)

ConnectNeurons connect two neurons. It creates synapse and add connection to input and output Neuron.

func ToJSON Uses

func ToJSON(network Perceptron) string

ToJSON dump and transform Perceptron to json string.

type CoreNeuron Uses

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 Dataset Uses

type Dataset [][2]Vector

Dataset - simple type for store input and expected Vectors.

type Neuron Uses

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

func HNeuron Uses

func HNeuron(weight float64) Neuron

HNeuron - creates hiddenNeuron.

func INeuron Uses

func INeuron(weight float64, connectTo chan float64) Neuron

INeuron - creates inputNeuron.

func ONeuron Uses

func ONeuron(weight float64, connectTo chan float64) Neuron

ONeuron - creates outputNeuron.

type Perceptron Uses

type Perceptron struct {
    // contains filtered or unexported fields
}

Perceptron implement Neural Network Perceptron by collect layers with Neurons and input/output channels.

func CreatePerceptron Uses

func CreatePerceptron(layers ...int) Perceptron

CreatePerceptron make new Perceptron NN with count of neurons in each Layer.

func FromJSON Uses

func FromJSON(jsonString string) Perceptron

FromJSON load json string and create Perceptron.

func (*Perceptron) Calculate Uses

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 Uses

func (n *Perceptron) ConnectLayers()

ConnectLayers create all to all connection between layers.

func (*Perceptron) RunNeurons Uses

func (n *Perceptron) RunNeurons()

RunNeurons create goroutines for all Neuron in Perceptron.

type PerceptronTrainer Uses

type PerceptronTrainer struct {
    Network *Perceptron
    Dataset Dataset
}

PerceptronTrainer is a trainer for Perceptron networks

func (*PerceptronTrainer) BackPropagation Uses

func (t *PerceptronTrainer) BackPropagation(times int)

BackPropagation train Network input Dataset for 'times' times.

type Vector Uses

type Vector []float64

Vector implement array of float64

Package varis imports 6 packages (graph). Updated 2018-08-02. Refresh now. Tools for package owners.