Skip to content

h-waldschmidt/nngo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

123 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nngo

Build Test codecov Go Report Card

Implementation of neural networks in Go.

Usage

package main

import (
	"fmt"
	"log"

	"github.com/h-waldschmidt/nngo/nngo"
	"gonum.org/v1/gonum/mat"
)

func main() {
	// initialize test and train data with labels
	trainData := mat.NewDense(2, 4, []float64{0, 0, 1, 1, 0, 1, 0, 1})
	trainLabels := mat.NewDense(2, 4, []float64{0, 0, 1, 1, 0, 1, 0, 1})
	testData := mat.NewDense(2, 4, []float64{0, 0, 1, 1, 0, 1, 0, 1})
	testLabels := mat.NewDense(2, 4, []float64{0, 0, 1, 1, 0, 1, 0, 1})

	splitSet := nngo.SplitSet{
		Test:  nngo.Set{*trainData, *trainLabels},
		Train: nngo.Set{*testData, *testLabels},
	}

	// create the network
	network, err := nngo.NewNetwork(
		[][]int{
			{2, 10, 2}, // input layer with input size of 2, output size of 10 and tanh as activation function
			{10, 2, 2}, // output layer with input size of 10, output size of 2 and tanh as activation function
		},
		0, // loss function is MSE
	)
	if err != nil {
		log.Fatal(err)
	}

	// train the network with 1000 epochs
	network.Train(&splitSet.Train, 1000, 0.1)

	// evaluate the performance of the network
	accuracy := network.EvaluateOneHot(&splitSet.Test)
	fmt.Printf("Accuracy on test data: %v", accuracy)
}

Same example and additional mnist example can be found in examples.

Eacher Layer is always specified as a triplet (e.g. {4, 5, 0} specifies a layer with 4 input, 5 output neurons and Sigmoid as a activation function).

Specification

As seen in the above example activation function an loss are specified with numbers

Activation

Sigmoid: 0
Relu: 1
Tanh: 2

Loss

MSE: 0
MAE: 1

About

Implementation of Neural Networks in golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages