ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - goml/gobrain: Neural Networks written in go
Neural Networks written in go. Contribute to goml/gobrain development by creating an account on GitHub.
Visit Site

GitHub - goml/gobrain: Neural Networks written in go

GitHub - goml/gobrain: Neural Networks written in go

gobrain

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 (
	"github.com/goml/gobrain"
	"math/rand"
)

func main() {
	// set the random seed to 0
	rand.Seed(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:

ff.Test(patterns)

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}
ff.Update(inputs)

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.

Changelog

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

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory