Neural Networks written in go



Neural Networks written in go

GoDoc Build Status

Getting Started

The version 1.0.0 includes just basic Neural Network functions such as Feed Forward and Elman Recurrent Neural Network. A simple Feed Forward Neural Network can be constructed and trained as follows:

package main

import (

func main() {
	// set the random seed to 0

	// create the XOR representation patter to train the network
	patterns := [][][]float64{
		{{0, 0}, {0}},
		{{0, 1}, {1}},
		{{1, 0}, {1}},
		{{1, 1}, {0}},

	// instantiate the Feed Forward
	ff := &gobrain.FeedForward{}

	// initialize the Neural Network;
	// the networks structure will contain:
	// 2 inputs, 2 hidden nodes and 1 output.
	ff.Init(2, 2, 1)

	// train the network using the XOR patterns
	// the training will run for 1000 epochs
	// the learning rate is set to 0.6 and the momentum factor to 0.4
	// use true in the last parameter to receive reports about the learning error
	ff.Train(patterns, 1000, 0.6, 0.4, true)

After running this code the network will be trained and ready to be used.

The network can be tested running using the Test method, for instance:


The test operation will print in the console something like:

[0 0] -> [0.057503945708445]  :  [0]
[0 1] -> [0.930100635071210]  :  [1]
[1 0] -> [0.927809966227284]  :  [1]
[1 1] -> [0.097408795324620]  :  [0]

Where the first values are the inputs, the values after the arrow -> are the output values from the network and the values after : are the expected outputs.

The method Update can be used to predict the output given an input, for example:

inputs := []float64{1, 1}

the output will be a vector with values ranging from 0 to 1.

In the example folder there are runnable examples with persistence of the trained network on file.

In example/02 the network is saved on file and in example/03 the network is loaded from file.

To run the example cd in the folder and run

go run main.go

Recurrent Neural Network

This library implements Elman's Simple Recurrent Network.

To take advantage of this, one can use the SetContexts function.

ff.SetContexts(1, nil)

In the example above, a single context will be created initialized with 0.5. It is also possible to create custom initialized contexts, for instance:

contexts := [][]float64{
	{0.5, 0.8, 0.1}

Note that custom contexts must have the same size of hidden nodes + 1 (bias node), in the example above the size of hidden nodes is 2, thus the context has 3 values.


  • 1.0.0 - Added Feed Forward Neural Network with contexts from Elman RNN
  • gobrain


    Hello Jonas,

    Thanks for creating gobrain.

    it would be nice to do the training on the gpu using ... there is already a golang wrapper for cuda available:

    If you want to do a task like image recognition using neural networks: ... it would be really slow on the cpu?

    Any thoughts about that?

    Have you also looked into?

    Thanks, Gerald

    opened by geraldstanje 6
  • Context weights

    Context weights

    Should not the contexts have a separate set of weights?

    	for i := 0; i < nn.NHiddens-1; i++ {
    		var sum float64
    		for j := 0; j < nn.NInputs; j++ {
    			sum += nn.InputActivations[j] * nn.InputWeights[j][i]
    		// compute contexts sum
    		for k := 0; k < len(nn.Contexts); k++ {
    			for j := 0; j < nn.NHiddens-1; j++ {
    				sum += nn.Contexts[k][j]
    		nn.HiddenActivations[i] = sigmoid(sum)

    Without ContextWeights, the contexts sum is equal for every hidden node and there's no reason to recalculate it for each one. Am I missing something?

    opened by thallingstad 4
  • Add weights for Elman SRN contexts

    Add weights for Elman SRN contexts

    As mentioned by me in issue #10.

    This adds ContextWeights and ContextChanges: 3-dimensional arrays of weights and changes, one matrix for each context layer. The weights are calculated just as if they were extra input layers.

    The contexts with weights are initialized in SetContexts just as before, so this should not break backward compatibility.

    opened by thallingstad 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
Go Machine Learning
Machine Learning algorithms written in Golang
Go Machine Learning
fonet is a deep neural network package for Go.

fonet fonet is a deep neural network package for Go. It's mainly created because I wanted to learn about neural networks and create my own package. I'

Barnabás Pataki 67 May 13, 2022
Artificial Neural Network

go-deep Feed forward/backpropagation neural network implementation. Currently supports: Activation functions: sigmoid, hyperbolic, ReLU Solvers: SGD,

Patrik Ehrencrona 365 May 15, 2022
Neural Network for Go.

gonet gonet is a Go module implementing multi-layer Neural Network. Install Install the module with: go get Import it in

Dat Hoang 74 Apr 21, 2022
onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.

This is a Go Interface to Open Neural Network Exchange (ONNX). Overview onnx-go contains primitives to decode a onnx binary model into a computation b

Olivier Wulveryck 388 May 1, 2022
Golang Neural Network

Varis Neural Networks with GO About Package Some time ago I decided to learn Go language and neural networks. So it's my variation of Neural Networks

Artem Filippov 44 Mar 20, 2022
A neural network library built in Go

go-mind A neural network library built in Go. Usage import "" m := mind.New(0.7, 10000, 3, "sigmoid") m.Learn([][]

Steven Miller 165 Mar 16, 2022
An implementation of Neural Turing Machines

Neural Turing Machines Package ntm implements the Neural Turing Machine architecture as described in A.Graves, G. Wayne, and I. Danihelka. arXiv prepr

Fumin 397 Apr 4, 2022
Example of Neural Network models of social and personality psychology phenomena

SocialNN Example of Neural Network models of social and personality psychology phenomena This repository gathers a collection of neural network models

null 6 Jan 15, 2022
Neural network in Go

network Package network is a simple implementation of a nonbiased neural network. The networks created by this package can be trained with backpropaga

Shingirai Chanakira 0 Nov 25, 2021
Go (Golang) encrypted deep learning library; Fully homomorphic encryption over neural network graphs

DC DarkLantern A lantern is a portable case that protects light, A dark lantern is one who's light can be hidden at will. DC DarkLantern is a golang i

Raven 1 Dec 2, 2021
Genetic Algorithms library written in Go / golang

Description Genetic Algorithms for Go/Golang Install $ go install git:// Compiling examples: $ git clone git://

Thomas Jager 191 May 7, 2022
A recommender system service based on collaborative filtering written in Go

Language: English | 中文 gorse: Go Recommender System Engine Build Coverage Report GoDoc RTD Demo gorse is an offline recommender system backend based o

Zhenghao Zhang 5.7k May 22, 2022
A Naive Bayes SMS spam classifier written in Go.

Ham (SMS spam classifier) Summary The purpose of this project is to demonstrate a simple probabilistic SMS spam classifier in Go. This supervised lear

Dan Wolf 11 Aug 17, 2021
k-means clustering algorithm implementation written in Go

kmeans k-means clustering algorithm implementation written in Go What It Does k-means clustering partitions a multi-dimensional data set into k cluste

Christian Muehlhaeuser 374 Apr 27, 2022
a* pathfinding algorithm written in go

astar a* (a-star) pathfinding algorithm written in go Wikipedia: EN: A* search algorithm DE: A*-Algorithmus Install go get[email protected]

Julian Pierer 26 Mar 21, 2022
A simple utility, written in Go, for interacting with Salesforce.

Salesforce CLI A simple utility, written in Go, for interacting with Salesforce. Currently only specific functionality is implemented, and the output

Darren Parkinson 0 Dec 14, 2021
A simple yet customisable program written in go to make hackerman-like terminal effects.

stuntman a simple program written in go to make you look like a hackerman Demo stuntman -binar -width 90 -color cyan stuntman -text -width 90 -vertgap

Solaris 12 May 20, 2022
Suricate-bank - API to transfer money between accounts at Suricate Bank,written in Go

⚠️ WORK IN PROGRESS ⚠️ Suricate Bank is an api that creates accounts and transfe

João Saraceni 11 May 8, 2022
ncurses matrix/log app written in go to visualize chess problems.

dorrella/matrix-curses Matrix using ncurses and gbin/goncurses. Visual matrix based puzzles Install need libncurses-dev. Probably hard to run on windo

null 0 Jan 12, 2022