neural

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: MIT Imports: 3 Imported by: 0

README

neural-go

Neural networks (deep feedforward)

package main

import (
  "fmt"
  "github.com/lukks/neural-go"
)

func main () {
  rgb := neural.NewNeural([]neural.Layer{
    neural.NewInputLayer(2, 8), // (inputs, neurons) is also a hidden layer
    neural.NewHiddenLayer(8),
    neural.NewOutputLayer(1),
  })

  for i := 0; i <= 5000; i++ {
    mse := rgb.LearnRaw([]float64{ 0.0, 0.0 }, []float64{ 0.0 }, 0.2)
    mse += rgb.LearnRaw([]float64{ 1.0, 0.0 }, []float64{ 1.0 }, 0.2)
    mse += rgb.LearnRaw([]float64{ 0.0, 1.0 }, []float64{ 1.0 }, 0.2)
    mse += rgb.LearnRaw([]float64{ 1.0, 1.0 }, []float64{ 0.0 }, 0.2)
    mse /= 4;

    if i % 1000 == 0 {
      fmt.Printf("iter %v, mse %f\n", i, mse)
    }
  }

  fmt.Printf("0, 0 [0] -> %f\n", rgb.Think([]float64{ 0.0, 0.0 }))
  fmt.Printf("1, 0 [1] -> %f\n", rgb.Think([]float64{ 1.0, 0.0 }))
  fmt.Printf("0, 1 [1] -> %f\n", rgb.Think([]float64{ 0.0, 1.0 }))
  fmt.Printf("1, 1 [0] -> %f\n", rgb.Think([]float64{ 1.0, 1.0 }))
}

Import

import "github.com/lukks/neural-go"

Features

Ranges

Set a range of values for every input and output.
So you use your values as you know but the neural get the values in raw (0-1).
Check examples/full.go for usage example.

Description

From my previous neural-amxx.

Structs
type Neuron struct
type Layer struct
type Neural struct
Methods
// low-level usage:
func NewNeuron (maxInputs int) Neuron {}
func (neuron *Neuron) Think (inputs []float64) float64 {}

func NewLayer (maxNeurons int, maxInputs int) Layer {}
func (layer *Layer) Think (inputs []float64) []float64 {}

func NewNeural (layers []Layer) Neural {}
func (neural *Neural) ThinkRaw (inputs []float64) []float64 {}
func (neural *Neural) LearnRaw (inputs []float64, outputs []float64, rate float64) float64 {}

// high-level usage:
func NewInputLayer (maxInputs int, maxNeurons int) Layer {}
func NewHiddenLayer (maxNeurons int) Layer {}
func NewOutputLayer (maxNeurons int) Layer {}
func (neural *Neural) InputRange (index int, min float64, max float64) {}
func (neural *Neural) OutputRange (index int, min float64, max float64) {}
func (neural *Neural) Think (inputs []float64) []float64 {}
func (neural *Neural) Learn (inputs []float64, outputs []float64, rate float64) float64 {}
Missing

Some methods that are not available yet:

func (neural *Neural) Save () {}
func (neural *Neural) Load () {}
func (neural *Neural) Delete () {}
func (neural *Neural) Reset () {}

Examples

Basic XOR examples/xor.go
RGB brightness examples/full.go

go run examples/full.go

Tests

There are no tests yet

Issues

Feedback, ideas, etc are very welcome so feel free to open an issue.

License

Code released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layer

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

func NewHiddenLayer

func NewHiddenLayer(maxNeurons int) Layer

func NewInputLayer

func NewInputLayer(maxInputs int, maxNeurons int) Layer

next methods are not actually needed but they are utilities for easy usage

func NewLayer

func NewLayer(maxNeurons int, maxInputs int) Layer

func NewOutputLayer

func NewOutputLayer(maxNeurons int) Layer

func (*Layer) Think

func (layer *Layer) Think(inputs []float64) []float64

type Neural

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

func NewNeural

func NewNeural(layers []Layer) Neural

func (*Neural) InputRange

func (neural *Neural) InputRange(index int, min float64, max float64)

func (*Neural) InputValuesToRaw

func (neural *Neural) InputValuesToRaw(inputs []float64) []float64

func (*Neural) Learn

func (neural *Neural) Learn(inputs []float64, outputs []float64, rate float64) float64

func (*Neural) LearnRaw

func (neural *Neural) LearnRaw(inputs []float64, outputs []float64, rate float64) float64

func (*Neural) OutputRange

func (neural *Neural) OutputRange(index int, min float64, max float64)

func (*Neural) OutputValuesFromRaw

func (neural *Neural) OutputValuesFromRaw(outputs []float64) []float64

func (*Neural) OutputValuesToRaw

func (neural *Neural) OutputValuesToRaw(outputs []float64) []float64

func (*Neural) Think

func (neural *Neural) Think(inputs []float64) []float64

func (*Neural) ThinkRaw

func (neural *Neural) ThinkRaw(inputs []float64) []float64

type Neuron

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

func NewNeuron

func NewNeuron(maxInputs int) Neuron

func (*Neuron) Think

func (neuron *Neuron) Think(inputs []float64) float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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