feedforward

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 10 Imported by: 16

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) Branch added in v0.0.8

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

func (*FeedforwardNetwork) Forget added in v0.0.11

func (f *FeedforwardNetwork) Forget()

Forget.

func (FeedforwardNetwork) Forward

func (f FeedforwardNetwork) Forward(in FeedforwardNetworkInput, l, worst, neg 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 added in v0.0.12

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

GetBits reports the number of bits predicted by this network

func (*FeedforwardNetwork) GetClasses added in v0.0.12

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

GetBits reports the number of classes predicted by this network

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) 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) Infer

Infer infers the network output based on input, after being trained by using Tally2 or Tally

func (FeedforwardNetwork) Infer2 added in v0.0.12

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

func (FeedforwardNetwork) Infer3 added in v0.0.8

Infer3 infers the network output based on input, after being trained by using Tally3

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) 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 added in v0.0.4

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) ReadCompressedWeights added in v0.0.6

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

ReadCompressedWeights reads model weights from a reader

func (*FeedforwardNetwork) ReadCompressedWeightsFromFile added in v0.0.6

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

ReadCompressedWeightsFromFile reads model weights from a lzw file

func (*FeedforwardNetwork) ReadZlibWeights added in v0.0.11

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

ReadZlibWeights reads model weights from a reader

func (*FeedforwardNetwork) ReadZlibWeightsFromFile added in v0.0.11

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

ReadZlibWeightsFromFile reads model weights from a lzw file

func (*FeedforwardNetwork) SetLayersP added in v0.0.4

func (f *FeedforwardNetwork) SetLayersP(premodulo uint32)

SetLayersP sets an input feature pre-modulo to layers.

func (FeedforwardNetwork) Shuffle added in v0.0.4

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

func (*FeedforwardNetwork) Tally

func (f *FeedforwardNetwork) Tally(in, output FeedforwardNetworkInput, worst int, tally *datasets.Tally, less func(i, j FeedforwardNetworkInput) bool)

Tally tallies the network on input/output pair with respect to to-be-trained worst hashtron. The tally is stored into thread safe structure Tally. Two ouputs i, j can be compared to be less worse using the function less (returning true if output i is less worse than output j).

func (*FeedforwardNetwork) Tally2 added in v0.0.4

func (f *FeedforwardNetwork) Tally2(in, output FeedforwardNetworkInput, worst int, tally *datasets.Tally,
	loss func(i FeedforwardNetworkInput) uint32)

Tally2 tallies the network like Tally, except it can also optimize n-way classifiers. Loss is 0 if the output is correct, below or equal to maxloss otherwise.

func (*FeedforwardNetwork) Tally3 added in v0.0.8

Tally3 tallies the network like Tally2, except it can also balance the dataset using input parity bit. Loss is 0 if the output is correct, below or equal to maxloss otherwise.

func (*FeedforwardNetwork) Tally4 added in v0.0.12

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

Tally3 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 added in v0.0.6

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

WriteCompressedWeights writes model weights to a writer

func (*FeedforwardNetwork) WriteCompressedWeightsToFile added in v0.0.6

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

WriteCompressedWeightsToFile writes model weights to a lzw file

func (*FeedforwardNetwork) WriteZlibWeights added in v0.0.11

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

WriteZlibWeights writes model weights to a writer

func (*FeedforwardNetwork) WriteZlibWeightsToFile added in v0.0.11

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 added in v0.0.12

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 added in v0.0.8

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

Jump to

Keyboard shortcuts

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