mind

package module
v0.0.0-...-6457c7d Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 4 Imported by: 1

README

go-mind

A neural network library built in Go.

Usage

import "github.com/stevenmiller888/go-mind"

m := mind.New(0.7, 10000, 3, "sigmoid")

m.Learn([][][]float64{
	{{0, 0}, {0}},
	{{0, 1}, {1}},
	{{1, 0}, {1}},
	{{1, 1}, {0}},
})

m.Predict([][]float64{
	{1, 0},
})

Note

Just built this to learn a little Go. Feedback welcome :)

License

MIT

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Version.

Variables

This section is empty.

Functions

func Activator

func Activator(f func(float64) float64) func(*mat64.Dense) *mat64.Dense

Activator returns the activation function.

func Format

func Format(examples [][][]float64) (*mat64.Dense, *mat64.Dense)

Format the examples.

func Htan

func Htan(z float64) float64

Htan calculates the hyperbolic tangent of `z`.

func Htanprime

func Htanprime(z float64) float64

Htanprime calculates the derivative of the hyperbolic tangent of `z`.

func Normals

func Normals(rows, cols int) *mat64.Dense

Normals returns a DenseMatrix filled with random values.

func Sigmoid

func Sigmoid(z float64) float64

Sigmoid calculates the sigmoid of `z`.

func SigmoidPrime

func SigmoidPrime(z float64) float64

SigmoidPrime calculates the sigmoid prime of `z`.

Types

type Mind

type Mind struct {
	LearningRate  float64                         // speed the network will learn at
	Iterations    int                             // number of training iterations
	HiddenUnits   int                             // number of units in hidden layer
	Activate      func(*mat64.Dense) *mat64.Dense // activation function
	ActivatePrime func(*mat64.Dense) *mat64.Dense // derivative of activation function
	Weights                                       // learning weights
	Results                                       // learning results
}

Mind represents the neural network.

func New

func New(rate float64, iterations int, units int, activator string) *Mind

New mind loaded with `rate`, `iterations`, and `units`.

func (*Mind) Back

func (m *Mind) Back(input *mat64.Dense, output *mat64.Dense)

Back propagate the error and update the weights.

func (*Mind) Forward

func (m *Mind) Forward(input *mat64.Dense)

Forward propagate the examples through the network.

func (*Mind) Learn

func (m *Mind) Learn(examples [][][]float64)

Learn from examples.

func (*Mind) Predict

func (m *Mind) Predict(input [][]float64) *mat64.Dense

Predict from input.

type Results

type Results struct {
	HiddenSum    *mat64.Dense
	HiddenResult *mat64.Dense
	OutputSum    *mat64.Dense
	OutputResult *mat64.Dense
}

Results represents, at a given unit, the output of multiplying the inputs and weights in all previous layers.

type Weights

type Weights struct {
	InputHidden  *mat64.Dense
	HiddenOutput *mat64.Dense
}

Weights represents the connections between units.

Directories

Path Synopsis
examples
xor

Jump to

Keyboard shortcuts

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