neural

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2017 License: GPL-3.0 Imports: 8 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 *Stimuli)

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 *Stimuli, percentage float64, mix int)

separateSet Stimuli training set in training and testing. TODO: create in-place rotation If passed mix is 0, training and testing set will be first merged, then splitted with given percentage. If passed mix is 1, training and testing set will be first merged, then shuffled, then splitted with given percentage.

func TrainPerceptron

func TrainPerceptron(perceptron *Perceptron, stimuli *Stimuli, 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 Stimuli

type Stimuli struct {

	// Set of stimulus for training
	Training []Stimulus
	// Set of stimulus for testing
	Testing []Stimulus
	// Percentage of strimulus for training and testing
	SplitPercentage float64
}

Stimuli struct represents a set of stimulus splitted in training and testing set

func LoadStimuliFromCSVFile

func LoadStimuliFromCSVFile(filePath string, splitPercentage float64, mix int) (Stimuli, error)

LoadStimuliFromCSVFile load a CSV dataset into Stimuli struct. If mix is 0, no shuffling will be performed. If 1, pseudo-random shuffling of line will be performed. It returns Stimuli struct splitting record in file with passed percentage.

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

Jump to

Keyboard shortcuts

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