gnn

package module
v0.0.0-...-a6366f5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: MIT Imports: 7 Imported by: 0

README

Build Status

GNN

Golang Neural Network (GNN) framework! GNN was built for educational purposes to learn about neural networks & goland! Currently this framework is able to implement simple fully connected networks.

Example

net := Net{
  NewFC(2, 4),
  &ReLU{},
  InitFC(4, 1),
  &Sigmoid{},
}

trainer = Trainer{
  Net:          net,
  Cost:         SE{}, // Standard Error Loss
  LearningRate: 0.1,
  Epochs:       10000,
  BatchSize:    4,
}

xor = data.Init(
  mat.InitRows(
    vec.Init(0, 0, 1, 1),
    vec.Init(0, 1, 1, 0),
  ),
  mat.InitRows(
    vec.Init(0, 1, 1, 0),
  ),
)


trainer.Train(xor)
predictions := trainer.Predict(xor.Data())

See trainer_test.go:TestTrainer for a worker example.

anynet used as reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cost

type Cost interface {
	Cost(exp, act mat.Matrix) mat.Matrix
	Der(exp, act mat.Matrix) mat.Matrix
}

Cost is the cost interface

type FullyConnected

type FullyConnected struct {
	Weights mat.Matrix
	Biases  vec.Vector
	// contains filtered or unexported fields
}

FullyConnected a fully connected network layer

func InitFC

func InitFC(weights mat.Matrix, biases vec.Vector) *FullyConnected

InitFC initializes a FC layer with the given weights and biases

func NewFC

func NewFC(in, out int) *FullyConnected

NewFC creates a net fully connected layer and initializes the weights using a Gaussian distribution

func (*FullyConnected) BackProp

func (f *FullyConnected) BackProp(t Trainer, dz mat.Matrix) mat.Matrix

BackProp applies the backpropogation operation of a fully connected layer and updates its parameters

func (*FullyConnected) Forward

func (f *FullyConnected) Forward(a mat.Matrix) mat.Matrix

Forward applies the forward operation of a fully connected layer

type Layer

type Layer interface {
	Forward(x mat.Matrix) mat.Matrix
	BackProp(t Trainer, partial mat.Matrix) mat.Matrix
}

Layer a layer in a neural network

type LearningRate

type LearningRate float64

LearningRate LearningRate

type Net

type Net []Layer

Net a neural network

func (Net) BackProp

func (n Net) BackProp(t Trainer, partial mat.Matrix)

BackProp updates the network parameters given the cost partial

func (Net) Forward

func (n Net) Forward(input mat.Matrix) mat.Matrix

Forward forwards the network

type ReLU

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

ReLU ReLU

func (*ReLU) BackProp

func (r *ReLU) BackProp(t Trainer, dz mat.Matrix) mat.Matrix

BackProp BackProp

func (*ReLU) Forward

func (r *ReLU) Forward(z mat.Matrix) mat.Matrix

Forward Forward

type SE

type SE struct{}

SE is the squared error struct

func (SE) Cost

func (s SE) Cost(exp, act mat.Matrix) mat.Matrix

Cost computes the squared error cost

func (SE) Der

func (s SE) Der(exp, act mat.Matrix) mat.Matrix

Der computes the squared error derivatives

type Sigmoid

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

Sigmoid is the sigmoid activation struct

func (*Sigmoid) BackProp

func (s *Sigmoid) BackProp(t Trainer, dz mat.Matrix) mat.Matrix

BackProp applies the sigmoid derivative to the given vector and returns the output

func (*Sigmoid) Forward

func (s *Sigmoid) Forward(z mat.Matrix) mat.Matrix

Forward applies the sigmoid function to the given matrix and returns the output

type Softmax

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

Softmax is the softmax activation struct

func (*Softmax) BackProp

func (s *Softmax) BackProp(t Trainer, dz mat.Matrix) mat.Matrix

BackProp applies the softmax derivative to the given matrix and returns the output

func (*Softmax) Forward

func (s *Softmax) Forward(z mat.Matrix) mat.Matrix

Forward applies the softmax function to each column

type Trainer

type Trainer struct {
	Net          Net          `validate:"required"`
	Cost         Cost         `validate:"required"`
	LearningRate LearningRate `validate:"required"`
	BatchSize    int          `validate:"required"`
	Epochs       int          `validate:"required"`
	Status       func(cost float64)
}

Trainer Trainer

func (Trainer) Predict

func (t Trainer) Predict(m mat.Matrix) mat.Matrix

func (Trainer) Train

func (t Trainer) Train(d data.DataSet)

Train Train

Directories

Path Synopsis
ext
csv
log

Jump to

Keyboard shortcuts

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