trainer

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Beta1 = 0.9
	Beta2 = 0.999
)

Variables

View Source
var (
	LearningRate = 0.01
	BatchSize    = 16384
)

Functions

func Run

func Run(
	ctx context.Context,
	datasetProvider IDatasetProvider,
	validationProvider IDatasetProvider,
	threads int,
	epochs int,
	sigmoidScale float64,
	netFolderPath string,
) error

func ValidationCost

func ValidationCost(output, target float64) float64

Types

type ActivationFn

type ActivationFn interface {
	Sigma(x float64) float64
	SigmaPrime(x float64) float64
}

type Gradient

type Gradient struct {
	Value float64
	M1    float64
	M2    float64
}

func (*Gradient) Apply

func (g *Gradient) Apply(elem *float64)

func (*Gradient) Calculate

func (g *Gradient) Calculate() float64

func (*Gradient) Reset

func (g *Gradient) Reset()

func (*Gradient) Update

func (g *Gradient) Update(delta float64)

type Gradients

type Gradients struct {
	Data []Gradient
	Rows int
	Cols int
}

func NewGradients

func NewGradients(rows, cols int) Gradients

func (*Gradients) AddMatrix

func (g *Gradients) AddMatrix(m *Matrix)

func (*Gradients) Apply

func (g *Gradients) Apply(m *Matrix)

type IDatasetProvider

type IDatasetProvider interface {
	Load(ctx context.Context, dataset chan<- domain.DatasetItem) error
}

type Matrix

type Matrix struct {
	Data []float64
	Rows int
	Cols int
}

func NewMatrix

func NewMatrix(rows, cols int) Matrix

func (*Matrix) Add

func (m *Matrix) Add(row, col int, delta float64)

func (*Matrix) Get

func (m *Matrix) Get(row, col int) float64

func (*Matrix) Reset

func (m *Matrix) Reset()

type Network

type Network struct {
	Id       uint32
	Topology Topology
	Weights  []Matrix
	Biases   []Matrix
}

Network is a neural network with 3 layers

func (*Network) Save

func (n *Network) Save(file string) error

Binary specification for the NNUE file: - All the data is stored in little-endian layout - All the matrices are written in column-major - The magic number/version consists of 4 bytes (int32):

  • 66 (which is the ASCII code for B), uint8
  • 90 (which is the ASCII code for Z), uint8
  • 2 The major part of the current version number, uint8
  • 0 The minor part of the current version number, uint8

- 4 bytes (int32) to denote the network ID - 4 bytes (int32) to denote input size - 4 bytes (int32) to denote output size - 4 bytes (int32) number to represent the number of inputs - 4 bytes (int32) for the size of each layer - All weights for a layer, followed by all the biases of the same layer - Other layers follow just like the above point

type Neuron

type Neuron struct {
	A, E, Prime float64
}

type ReLu

type ReLu struct{}

func (*ReLu) Sigma

func (s *ReLu) Sigma(x float64) float64

func (*ReLu) SigmaPrime

func (s *ReLu) SigmaPrime(x float64) float64

type Sample

type Sample struct {
	Input  []int16
	Target float32
}

type Sigmoid

type Sigmoid struct {
	SigmoidScale float64
}

func (*Sigmoid) Sigma

func (s *Sigmoid) Sigma(x float64) float64

func (*Sigmoid) SigmaPrime

func (s *Sigmoid) SigmaPrime(x float64) float64

type ThreadData

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

type Topology

type Topology struct {
	Inputs        uint32
	Outputs       uint32
	HiddenNeurons []uint32
}

func (*Topology) LayerSize

func (t *Topology) LayerSize() int

type Trainer

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

func NewTrainer

func NewTrainer(training, validation []Sample,
	topology []int, threads int, seed int64, sigmoidScale float64) *Trainer

func (*Trainer) Train

func (t *Trainer) Train(epochs int, binFolderPath string) error

Jump to

Keyboard shortcuts

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