neuralnet

package module
v0.0.0-...-5a348da Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2018 License: MIT Imports: 6 Imported by: 0

README

neuralnet

Create simple feed forward networks in Go

GoDoc Build Status codecov rcard

Getting Started

Create a network with three input neurons, two hidden layers with four and two neurons and an output layer with one neuron:

n := neuralnet.NewNeuralNetwork([]uint{3, 4, 2, 1})
Basic usage

Train the network:

input := []float64{1.0, 1.0}
output := []float64{0.0}
n.Train(input, output, 0.25)

Predict the output:

prediction := n.Predict(data)
Persisting the network

Persist the network:

file, _ := os.Create("network.json")
n.Dump(file)

Load persisted network:

file, _ := os.Open("network.json")
n, _ = neuralnet.LoadNeuralNetwork(ifile)

For more detailed info see examples folder

Documentation

Overview

Package neuralnet provides basic feed-forward mlp neural-networks

Index

Constants

This section is empty.

Variables

R is the source to be used for the initial random weights

Functions

This section is empty.

Types

type NeuralNetwork

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

NeuralNetwork that contains layers, neurons and biases. It provides a fully connected network for supervised learning

func LoadNeuralNetwork

func LoadNeuralNetwork(r io.Reader) (*NeuralNetwork, error)

LoadNeuralNetwork returns a previously dumped network based on the encoded data from the io.Reader r

func NewNeuralNetwork

func NewNeuralNetwork(layers []uint) *NeuralNetwork

NewNeuralNetwork returns a randomized network with the specified number of layers and neurons. Example: []uint{6, 3, 2, 2} would create a network with 6 input neurons, 2 hidden layers with 3 and 2 neurons and an output layer with 2 neurons

func (*NeuralNetwork) Dump

func (n *NeuralNetwork) Dump(w io.Writer) error

Dump marshals the neural network to json and writes it to the specified io.Writer w

func (*NeuralNetwork) Predict

func (n *NeuralNetwork) Predict(input []float64) []float64

Predict will feedforward the input and then return the prediction

func (*NeuralNetwork) Train

func (n *NeuralNetwork) Train(input, output []float64, eta float64)

Train will feedforward the input and then backpropagate to reduce error on output using learning rate eta

Directories

Path Synopsis
examples
xor

Jump to

Keyboard shortcuts

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