nets

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package nets provides a standard interface for interacting with neural networks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DerivedF

func DerivedF(y float32) float32

DerivedF is the derivative of the bipolar sigmoid

func F

func F(x float32) float32

F is the bipolar sigmoid function

func ID2Type

func ID2Type(id string) (string, error)

ID2Type takes a string and attempts to extract a net ID from it, when it comes to errors there can be false negatives but not false positives (no error doesn't necessarily mean it's a good ID)

func List

func List(offset, limit int, pattern string, nps paramstores.NetParamStore) ([]types.BriefNet, int, error)

List encapsulates the logic required to fill in BriefNet objects from the IDs of nets in the store

func MLPTopology

func MLPTopology(inputs, outputs, hLayers int) []int

MLPTopology returns an array of neurons per layer given the number of inputs, outputs and hidden layers

func Required

func Required(inputs, outputs, hLayers int, conf config.Config) int

Required returns the number of patterns required to train a net (of the most demanding type) with the specified topology

func Trainer

func Trainer(c chan types.TrainRequest, conf config.Config) error

Trainer listens for requests to train neural nets with new points

Types

type Chromosome

type Chromosome struct {
	ActivationFunc string
	Fitness        float32 // Aptitude for infering outputs for the given inputs
	HLayers        int     // Number of hidden layers
	LearningRate   float32
	Type           string
	Net            Network
}

Chromosome represents a neural network configuration

func (*Chromosome) Check

func (c *Chromosome) Check(tr types.TrainRequest, outputs []string, points []pointstores.Point, params config.MLParams) error

Check trains a network with the chromosome's config and updates its fitness based on the accuracy

func (Chromosome) Crossover

func (c Chromosome) Crossover(b Chromosome, n int) []Chromosome

Crossover exchanges n+1 parameters between the chromosomes to create two new configurations

func (*Chromosome) Mutate

func (c *Chromosome) Mutate(gene int)

Mutate randomly alters the given gene

type MLP

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

MLP holds the neurons and thus serves to keep track of the values through the network during training and operation

func MLPFromParams

func MLPFromParams(id string, np paramstores.MLPParams) (*MLP, error)

MLPFromParams returns a multilayer perceptron network initialized with the specified params

func NewMLP

func NewMLP(id string, inputs, outputs []string, chromosome Chromosome) (*MLP, error)

NewMLP returns a multilayer perceptron net built from scratch with the requested inputs, outputs and hidden layers

func (*MLP) Evaluate

func (net *MLP) Evaluate(inputs map[string]float32) (map[string]float32, error)

Evaluate will return the net's output for the given input vector

func (*MLP) ID

func (net *MLP) ID() string

ID is a getter for the ID field

func (*MLP) Params

func (net *MLP) Params() paramstores.NetParams

Params returns the network's params

func (*MLP) Train

func (net *MLP) Train(points []pointstores.Point, maxEpoch int, errMargin, testSet, tolerance float32) (float32, error)

Train will use the specified input/output pairs to modify the net so the behaviour of its connections is closer to that of the unknown relationships it's intended to mimic

type Network

type Network interface {
	// This method should return the outputs of feeding the specified inputs into the net
	Evaluate(inputs map[string]float32) (map[string]float32, error)
	ID() string
	// This method should return the net's params
	Params() paramstores.NetParams
	// This method should feed the training pairs into the net and update its params in the net param storage when
	// it's done
	Train(points []pointstores.Point, maxEpoch int, errMargin, testSet, tolerance float32) (float32, error)
}

Network represents the neural net implementation that is being used

func LoadNetwork

func LoadNetwork(id, nType string, nps paramstores.NetParamStore) (Network, error)

LoadNetwork is used to retrieve network params for a given ID and build a network object with them. When they can't be found (nil, nil) will be returned

func NewNetwork

func NewNetwork(id string, inputs, outputs []string, chromosome Chromosome) (Network, error)

NewNetwork returns an initialized neural network of the type specified in the configuration

type Neuron

type Neuron struct {
	Delta float32

	Value float32
	// contains filtered or unexported fields
}

Neuron holds the state of the smallest component in a neural net

func (*Neuron) AddInput

func (n *Neuron) AddInput(a *Neuron, weight *float32)

AddInput configures a connection between two neurons

func (*Neuron) RefreshDelta

func (n *Neuron) RefreshDelta() float32

RefreshDelta will update a neuron's deviation from the desired output

func (*Neuron) RefreshValue

func (n *Neuron) RefreshValue() float32

RefreshValue will update a neuron's output with the current value and weight of its inputs

type Population

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

Population represents a collection of individuals and their metadata

func NewPopulation

func NewPopulation(params config.MLParams) *Population

NewPopulation creates a new set of individuals and initializes their metadata

func (*Population) Optimal

func (pop *Population) Optimal(tr types.TrainRequest, outputs []string, points []pointstores.Point) (Network, error)

Optimal uses a genetic algorithm to find the config that results in the most accurate net for the given points and returns that net

Directories

Path Synopsis
Package paramstores contains the implementation of all the supported storage adapters for the network parameters
Package paramstores contains the implementation of all the supported storage adapters for the network parameters

Jump to

Keyboard shortcuts

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