neural

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: GPL-3.0 Imports: 9 Imported by: 2

Documentation

Overview

Neural provides struct to represents most common neural networks model and algorithms to train / test them.

Neural provides struct to represents most common neural networks model and algorithms to train / test them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accuracy

func Accuracy(actual []float64, predicted []float64) (int, float64)

Accuracy calculate percentage of equal values between two float64 based slices. It returns int number and a float64 percentage value of corrected values.

func Predict

func Predict(perceptron *Perceptron, stimulus *Stimulus) float64

Predict performs a perceptron prediction to passed stimulus. It returns a float64 binary predicted value.

func RandomPerceptronInit

func RandomPerceptronInit(perceptron *Perceptron)

RandomPerceptronInit initialize perceptron weight, bias and learning rate using NormFloat64 random value.

func RawExpectedConversion

func RawExpectedConversion(stimuli []Stimulus)

RawExpectedConversion converts (string) raw expected values in stimuli training / testing sets to float64 values It works on stimule struct (pointer) passed. It doens't returns nothing

func SeparateSet

func SeparateSet(stimuli []Stimulus, percentage float64, shuffle int) (train []Stimulus, test []Stimulus)

SeparateSet split an array of stimuli in training and testing. if shuffle is 0 the function takes the first percentage items as train and the other as test otherwise the stimuli array is shuffled before partitioning

func TrainPerceptron

func TrainPerceptron(perceptron *Perceptron, stimuli []Stimulus, epochs int, init int)

TrainPerceptron trains a passed perceptron with stimuli passed, for specified number of epoch. If init is 0, leaves weights unchanged before training. If init is 1, reset weights and bias of perceptron before training.

func UpdateWeights

func UpdateWeights(perceptron *Perceptron, stimulus *Stimulus) (float64, float64)

UpdateWeights performs update in perceptron weights with respect to passed stimulus. It returns error of prediction before and after updating weights.

Types

type Perceptron

type Perceptron struct {

	// Weights represents Perceptron vector representation
	Weights []float64
	// Bias represents Perceptron natural propensity to spread signal
	Bias float64
	// Lrate represents learning rate of perceptron
	Lrate float64
}

Perceptron struct represents a simple Perceptron network with a slice of n weights.

type Stimulus

type Stimulus struct {

	// Features that describe the stimulus
	Dimensions []float64
	// Raw (usually string) expected value
	RawExpected string
	// Numeric representation of expected value
	Expected float64
}

Stimulus struct represents one stimulus with dimensions and desired value

func LoadStimuliFromCSVFile

func LoadStimuliFromCSVFile(filePath string) ([]Stimulus, error)

LoadStimuliFromCSVFile load a CSV dataset into an array of Stimulus.

Jump to

Keyboard shortcuts

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