feedforward

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package feedforward implements a feedforward network type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FeedforwardNetwork

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

FeedforwardNetwork is the feedforward network

func (*FeedforwardNetwork) AnyTally

func (f *FeedforwardNetwork) AnyTally(io FeedforwardNetworkParityInOutput, worst []int, t datasets.AnyTally,
	loss func(actual, expected, mask uint32) uint32)

func (FeedforwardNetwork) Branch

func (f FeedforwardNetwork) Branch(reverse bool) (o []int)

func (*FeedforwardNetwork) Forget

func (f *FeedforwardNetwork) Forget()

Forget.

func (FeedforwardNetwork) Forward

func (f FeedforwardNetwork) Forward(in FeedforwardNetworkInput, l int, worstneg ...int) (inter Intermediate, computed []bool)

Forward solves the intermediate value (net output after layer l based on that layer's input in) and the bit returned by worst hashtron is optionally negated (using neg == 1) and returned as computed.

func (*FeedforwardNetwork) GetBits

func (f *FeedforwardNetwork) GetBits() (ret byte)

GetBits reports the number of bits predicted by this network

func (*FeedforwardNetwork) GetClasses

func (f *FeedforwardNetwork) GetClasses() (ret uint16)

GetBits reports the number of classes predicted by this network

func (FeedforwardNetwork) GetFrontBase

func (f FeedforwardNetwork) GetFrontBase(n int) (o int)

GetFrontBase returns the base number of hashtron for front layer. Each Layer and LayerPA counts as a front layer here.

func (FeedforwardNetwork) GetFrontLayer

func (f FeedforwardNetwork) GetFrontLayer(n int) int

GetLayer gets the layer number based on front layer number. Returns -1 on failure.

func (FeedforwardNetwork) GetFrontOffset

func (f FeedforwardNetwork) GetFrontOffset(n int) (o int)

GetFrontBase returns the offset number for front layer feature. Each Layer and LayerPA counts as a front layer here.

func (FeedforwardNetwork) GetHashtron

func (f FeedforwardNetwork) GetHashtron(n int) *hashtron.Hashtron

GetHashtron gets n-th hashtron pointer in the network. You can currently write a new hashtron into the pointer, but you might not be able to in the future.

func (*FeedforwardNetwork) GetLastCells

func (f *FeedforwardNetwork) GetLastCells() (ret byte)

GetLastCells gets last cells

func (FeedforwardNetwork) GetLayer

func (f FeedforwardNetwork) GetLayer(n int) int

GetLayer gets the layer number of hashtron based on hashtron number. Returns -1 on failure.

func (FeedforwardNetwork) GetLayerPosition

func (f FeedforwardNetwork) GetLayerPosition(l, n int) int

GetLayerPosition gets the position of hashtron within layer based on the overall hashtron number and overall layer. Returns -1 on failure.

func (FeedforwardNetwork) GetPosition

func (f FeedforwardNetwork) GetPosition(n int) int

GetPosition gets the position of hashtron within layer based on the overall hashtron number. Returns -1 on failure.

func (FeedforwardNetwork) Infer2

Infer2 infers the network output based on input, after being trained by using Tally4. This applies parity.

func (FeedforwardNetwork) IsMapLayerOf

func (f FeedforwardNetwork) IsMapLayerOf(n int) bool

IsMapLayerOf checks if hashtron n lies in the final layer of the network.

func (FeedforwardNetwork) Len

func (f FeedforwardNetwork) Len() (o int)

Len returns the number of hashtrons which need to be trained inside the network.

func (FeedforwardNetwork) LenFrontLayers

func (f FeedforwardNetwork) LenFrontLayers() (o int)

LenLayers returns the number of front layers. Each Layer and LayerPA counts as a front layer here.

func (FeedforwardNetwork) LenHashtronLayers

func (f FeedforwardNetwork) LenHashtronLayers() (l int)

LenHashtronLayers returns the number of hashtron layers. Each Layer (not Combiner) counts as a layer here.

func (FeedforwardNetwork) LenLayers

func (f FeedforwardNetwork) LenLayers() int

LenLayers returns the number of layers. Each Layer and Combiner counts as a layer here.

func (*FeedforwardNetwork) NewCombiner

func (f *FeedforwardNetwork) NewCombiner(layer layer.Layer)

NewCombiner adds a combiner layer to the end of network

func (*FeedforwardNetwork) NewLayer

func (f *FeedforwardNetwork) NewLayer(n int, bits byte)

NewLayer adds a hashtron layer to the end of network with n hashtrons, each recognizing bits-bits.

func (*FeedforwardNetwork) NewLayerP

func (f *FeedforwardNetwork) NewLayerP(n int, bits byte, premodulo uint32)

NewLayerP adds a hashtron layer to the end of network with n hashtrons, each recognizing bits-bits, and input feature pre-modulo.

func (*FeedforwardNetwork) NewLayerPA

func (f *FeedforwardNetwork) NewLayerPA(n int, bits byte, premodulo uint32)

NewLayerPA adds a hashtron layer to the end of network with n hashtrons, each recognizing bits-bits, and input feature pre-modulo and pre-addition.

func (*FeedforwardNetwork) NewLayerPI

func (f *FeedforwardNetwork) NewLayerPI(n int, bits byte, premodulo uint32)

NewLayerPI adds a hashtron layer to the end of network with n hashtrons, each recognizing bits-bits, and input feature pre-modulo and inter-addition.

func (*FeedforwardNetwork) PreTally4

func (f *FeedforwardNetwork) PreTally4(io FeedforwardNetworkParityInOutput, worst [2]int, dist datasets.AnyTally,
	loss func(actual, expected, mask uint32) uint32)

PreTally4 preTallys two worst hashtrons together for parity-based outputs Similar to preTally2 but handles parity input/output and power-of-2 classification

func (*FeedforwardNetwork) ReadCompressedWeights

func (f *FeedforwardNetwork) ReadCompressedWeights(w io.Reader) error

ReadCompressedWeights reads model weights from a reader

func (*FeedforwardNetwork) ReadCompressedWeightsFromFile

func (f *FeedforwardNetwork) ReadCompressedWeightsFromFile(name string) error

ReadCompressedWeightsFromFile reads model weights from a lzw file

func (*FeedforwardNetwork) ReadZlibWeights

func (f *FeedforwardNetwork) ReadZlibWeights(w io.Reader) error

ReadZlibWeights reads model weights from a reader

func (*FeedforwardNetwork) ReadZlibWeightsFromFile

func (f *FeedforwardNetwork) ReadZlibWeightsFromFile(name string) error

ReadZlibWeightsFromFile reads model weights from a lzw file

func (FeedforwardNetwork) Sequence

func (f FeedforwardNetwork) Sequence(reverse bool) (o []int)

func (*FeedforwardNetwork) SetLayersP

func (f *FeedforwardNetwork) SetLayersP(premodulo uint32)

SetLayersP sets an input feature pre-modulo to layers.

func (FeedforwardNetwork) Shuffle

func (f FeedforwardNetwork) Shuffle(reverse bool) (o []int)

func (*FeedforwardNetwork) Tally4

func (f *FeedforwardNetwork) Tally4(io FeedforwardNetworkParityInOutput, worst int, tally datasets.AnyTally,
	loss func(actual, expected, mask uint32) uint32)

Tally4 tallies the network on ParityInOutput, tuning the worst-th hashtron in the network f storing data in tally. Loss can be nil if predicting power of 2 classes, or an actual minus expected difference or any other loss (0 means correct).

func (*FeedforwardNetwork) WriteCompressedWeights

func (f *FeedforwardNetwork) WriteCompressedWeights(w io.Writer) error

WriteCompressedWeights writes model weights to a writer

func (*FeedforwardNetwork) WriteCompressedWeightsToFile

func (f *FeedforwardNetwork) WriteCompressedWeightsToFile(name string) error

WriteCompressedWeightsToFile writes model weights to a lzw file

func (*FeedforwardNetwork) WriteZlibWeights

func (f *FeedforwardNetwork) WriteZlibWeights(w io.Writer) error

WriteZlibWeights writes model weights to a writer

func (*FeedforwardNetwork) WriteZlibWeightsToFile

func (f *FeedforwardNetwork) WriteZlibWeightsToFile(name string) error

WriteZlibWeightsToFile writes model weights to a lzw file

type FeedforwardNetworkInput

type FeedforwardNetworkInput interface {
	Feature(n int) uint32
}

FeedforwardNetworkInput is one individual input to the feedforward network

type FeedforwardNetworkParityInOutput

type FeedforwardNetworkParityInOutput interface {
	Feature(n int) uint32
	Parity() uint16
	Output() uint16
}

FeedforwardNetworkParityInOutput is one individual sample to the feedforward network with parity and expected network output

type FeedforwardNetworkParityInput

type FeedforwardNetworkParityInput interface {
	Feature(n int) uint32
	Parity() bool
}

FeedforwardNetworkParityInput is one individual input to the feedforward network with parity

type Intermediate

type Intermediate interface {

	// Feature extracts n-th feature from Intermediate
	Feature(n int) uint32

	// Disregard reports whether Intermediate doesn't regard n-th bit as affecting the output
	Disregard(n int) bool
}

Intermediate is an intermediate value used as both layer input and layer output in optimization

type SingleValue

type SingleValue uint32

SingleValue is a single value returned by the final layer

func (SingleValue) Disregard

func (v SingleValue) Disregard(n int) bool

Disregard reports whether SingleValue doesn't regard n-th bit as affecting the output

func (SingleValue) Feature

func (v SingleValue) Feature(n int) uint32

Feature extracts the feature from SingleValue