neural

package module
v0.0.0-...-2a14176 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 9 Imported by: 0

README

neural

neural network for golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(w io.Writer, p *Neural) error

func Learn

func Learn(p *Neural, samples []Sample, learnRate float64, epochMax int,
	f func(epoch int, averageCost float64) bool) error

func NormalizeInputs

func NormalizeInputs(samples []Sample)

func OneHot

func OneHot(n, i int) []float64

func WriteFile

func WriteFile(filename string, p *Neural) error

Types

type ActivationFunc

type ActivationFunc interface {
	Func(x float64) float64        // f(x)
	Derivative(fx float64) float64 // {\frac {\partial f(x)}{\partial x}}
}

The activation function

func MakeActivationFunc

func MakeActivationFunc(at ActivationType) ActivationFunc

type ActivationType

type ActivationType int
const (
	ActLinear ActivationType = iota
	ActStep
	ActReLU
	ActSigmoid
	ActTanh
	ActSoftmax
)

type BP

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

Backpropagation

func NewBP

func NewBP(p *Neural, cf CostFunc) *BP

func (*BP) LearnSample

func (bp *BP) LearnSample(sample Sample)

func (*BP) LearnSamples

func (bp *BP) LearnSamples(samples []Sample) (averageCost float64)

func (*BP) SampleCost

func (bp *BP) SampleCost(sample Sample) (cost float64)

func (*BP) SetLearningRate

func (bp *BP) SetLearningRate(learningRate float64)

type BinaryCrossEntropy

type BinaryCrossEntropy struct{}

func (BinaryCrossEntropy) Func

func (BinaryCrossEntropy) Func(t, x []float64) float64

t[i] - ideal output = [0 or 1] x[i] - real output = [0..1]

type CostFunc

type CostFunc interface {
	Func(t, x []float64) float64 // t - ideal value
	Derivative(ti, xi float64) float64
}
var CFMeanSquared CostFunc = costMeanSquared{}

type CrossEntropy

type CrossEntropy struct{}

func (CrossEntropy) Derivative

func (CrossEntropy) Derivative(ti, xi float64) float64

func (CrossEntropy) Func

func (CrossEntropy) Func(t, x []float64) float64

t[i] - ideal output = [0 or 1] x[i] - real output = [0..1]

type LayerInfo

type LayerInfo struct {
	ActivationType ActivationType
	Neurons        int
}

func MakeLayers

func MakeLayers(at ActivationType, ds ...int) []LayerInfo

type Linear

type Linear struct{}

Linear or Identity

func (Linear) Derivative

func (Linear) Derivative(fx float64) float64

func (Linear) Func

func (Linear) Func(x float64) float64

type Logistic

type Logistic struct {
	Alpha float64
}

func (Logistic) Derivative

func (p Logistic) Derivative(fx float64) float64

func (Logistic) Func

func (p Logistic) Func(x float64) float64

type Neural

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

Feedforward neural network

func Decode

func Decode(r io.Reader) (*Neural, error)

func NewNeural

func NewNeural(rs []LayerInfo) (*Neural, error)

func ReadFile

func ReadFile(filename string) (*Neural, error)

func (*Neural) Calculate

func (p *Neural) Calculate()

forward

func (*Neural) GetOutputs

func (p *Neural) GetOutputs(outputs []float64)

func (*Neural) RandomizeWeights

func (p *Neural) RandomizeWeights()

func (*Neural) SetInputs

func (p *Neural) SetInputs(inputs []float64)

func (*Neural) Topology

func (p *Neural) Topology() []int

type ReLU

type ReLU struct{}

func (ReLU) Derivative

func (ReLU) Derivative(fx float64) float64

func (ReLU) Func

func (ReLU) Func(x float64) float64

type Sample

type Sample struct {
	Inputs  []float64
	Outputs []float64
}

type Sigmoid

type Sigmoid struct{}

func (Sigmoid) Derivative

func (Sigmoid) Derivative(fx float64) float64

sigmoidPrime implements the derivative of the sigmoid function for backpropagation.

func (Sigmoid) Func

func (Sigmoid) Func(x float64) float64

Sigmoid implements the sigmoid function for use in activation functions.

type Step

type Step struct{}

Binary Step

func (Step) Derivative

func (Step) Derivative(fx float64) float64

func (Step) Func

func (Step) Func(x float64) float64

type Tanh

type Tanh struct{}

range: (-1, 1)

func (Tanh) Derivative

func (Tanh) Derivative(fx float64) float64

func (Tanh) Func

func (Tanh) Func(x float64) float64

Directories

Path Synopsis
dataset
examples
mul
ssd

Jump to

Keyboard shortcuts

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