popcode

package
v2.0.0-dev0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 6 Imported by: 3

README

Docs: GoDoc

Package popcode provides population code encoding and decoding support functionality, in 1D and 2D.

popcode.OneD

popcode.OneD Encode method turns a single scalar value into a 1D population code according to a set of parameters about the nature of the population code, range of values to encode, etc.

Decode takes a distributed pattern of activity and decodes a scalar value from it, using activation-weighted average based on tuning value of individual units.

popcode.TwoD

popcode.TwoD likewise has Encode and Decode methods for 2D gaussian-bumps that simultaneously encode a 2D value such as a 2D position.

popcode.Ring

popcode.Ring is a version of popcode.OneD for values that wrap-around, such as an angle -- set the Min and Max to the exact values with no extra (e.g., 0, 360 for angle).

Documentation

Overview

Package `popcode` provides population code encoding and decoding support functionality, in 1D and 2D.

`popcode.OneD` `Encode` method turns a scalar value into a 1D population code according to a set of parameters about the nature of the population code, range of values to encode, etc.

`Decode` takes a distributed pattern of activity and decodes a scalar value from it, using activation-weighted average based on tuning value of individual units.

`popcode.TwoD` likewise has `Encode` and `Decode` methods for 2D gaussian-bumps that simultaneously encode a 2D value such as a 2D position.

The `add` option to the Encode methods allows multiple values to be encoded, and `DecodeNPeaks` allows multiple to be decoded, using a neighborhood around local maxima.

Index

Constants

View Source
const (
	// Add is used for popcode Encode methods, add arg -- indicates to add values
	// to any existing values in the target vector / tensor:
	// used for encoding additional values (see DecodeN for decoding).
	Add = true

	// Set is used for popcode Encode methods, add arg -- indicates to set values
	// in any existing values in the target vector / tensor:
	// used for encoding first / only values.
	Set = false
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OneD

type OneD struct {

	// how to encode the value
	Code PopCodes

	// minimum value representable -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode
	Min float32

	// maximum value representable -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode
	Max float32

	// sigma parameter of a gaussian specifying the tuning width of the coarse-coded units, in normalized 0-1 range
	Sigma float32 `default:"0.2"`

	// ensure that encoded and decoded value remains within specified range
	Clip bool

	// for decoding, threshold to cut off small activation contributions to overall average value (i.e., if unit's activation is below this threshold, it doesn't contribute to weighted average computation)
	Thr float32 `default:"0.1"`

	// minimum total activity of all the units representing a value: when computing weighted average value, this is used as a minimum for the sum that you divide by
	MinSum float32 `default:"0.2"`
}

popcode.OneD provides encoding and decoding of population codes, used to represent a single continuous (scalar) value across a population of units / neurons (1 dimensional)

func (*OneD) Decode

func (pc *OneD) Decode(pat []float32) float32

Decode decodes value from a pattern of activation as the activation-weighted-average of the unit's preferred tuning values. must have 2 or more values in pattern pat.

func (*OneD) DecodeNPeaks

func (pc *OneD) DecodeNPeaks(pat []float32, nvals, width int) []float32

DecodeNPeaks decodes N values from a pattern of activation using a neighborhood of specified width around local maxima, which is the amount on either side of the central point to accumulate (0 = localist, single points, 1 = +/- 1 point on either side, etc). Allocates a temporary slice of size pat, and sorts that: relatively expensive

func (*OneD) Defaults

func (pc *OneD) Defaults()

func (*OneD) Encode

func (pc *OneD) Encode(pat *[]float32, val float32, n int, add bool)

Encode generates a pattern of activation of given size to encode given value. n must be 2 or more. pat slice will be constructed if len != n. If add == false (use Set const for clarity), values are set to pattern else if add == true (Add), then values are added to any existing, for encoding additional values in same pattern.

func (*OneD) SetRange

func (pc *OneD) SetRange(min, max, sigma float32)

SetRange sets the min, max and sigma values

func (*OneD) ShouldShow

func (pc *OneD) ShouldShow(field string) bool

func (*OneD) Values

func (pc *OneD) Values(vals *[]float32, n int)

Values sets the vals slice to the target preferred tuning values for each unit, for a distribution of given size n. n must be 2 or more. vals slice will be constructed if len != n

type PopCodes

type PopCodes int
const (
	// GaussBump = gaussian bump, with value = weighted average of tuned unit values
	GaussBump PopCodes = iota

	// Localist = each unit represents a distinct value; intermediate values represented by graded activity of neighbors; overall activity is weighted-average across all units
	Localist
)

type Ring

type Ring struct {
	OneD

	// low-end encoding vector
	LowVec []float32 `view:"-"`

	// high-end encoding vector
	HighVec []float32 `view:"-"`
}

Ring is a OneD popcode that encodes a circular value such as an angle that wraps around at the ends. It uses two internal vectors to render the wrapped-around values into, and then adds them into the final result. Unlike regular PopCodes, the Min and Max should represent the exact range of the value (e.g., 0 to 360 for angle) with no extra on the ends, as that extra will wrap around to the other side in this case.

func (*Ring) AllocVecs

func (pc *Ring) AllocVecs(n int)

AllocVecs allocates internal LowVec, HighVec storage, allowing for variable lengths to be encoded using same object, growing capacity to max, but using exact amount each time

func (*Ring) Decode

func (pc *Ring) Decode(pat []float32) float32

Decode decodes value from a pattern of activation as the activation-weighted-average of the unit's preferred tuning values. pat pattern must be len >= 2

func (*Ring) Encode

func (pc *Ring) Encode(pat *[]float32, val float32, n int)

Encode generates a pattern of activation of given size to encode given value. n must be 2 or more. pat slice will be constructed if len != n

func (*Ring) EncodeImpl

func (pc *Ring) EncodeImpl(pat *[]float32, val float32, n int)

EncodeImpl generates a pattern of activation of given size to encode given value. n must be 2 or more. pat slice will be constructed if len != n

func (*Ring) Values

func (pc *Ring) Values(vals *[]float32, n int)

Values sets the vals slice to the target preferred tuning values for each unit, for a distribution of given size n. n must be 2 or more. vals slice will be constructed if len != n

type TwoD

type TwoD struct {

	// how to encode the value
	Code PopCodes

	// minimum value representable on each dim -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode
	Min math32.Vector2

	// maximum value representable on each dim -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode
	Max math32.Vector2

	// sigma parameters of a gaussian specifying the tuning width of the coarse-coded units, in normalized 0-1 range
	Sigma math32.Vector2 `default:"0.2"`

	// ensure that encoded and decoded value remains within specified range -- generally not useful with wrap
	Clip bool

	// x axis wraps around (e.g., for periodic values such as angle) -- encodes and decodes relative to both the min and max values
	WrapX bool

	// y axis wraps around (e.g., for periodic values such as angle) -- encodes and decodes relative to both the min and max values
	WrapY bool

	// threshold to cut off small activation contributions to overall average value (i.e., if unit's activation is below this threshold, it doesn't contribute to weighted average computation)
	Thr float32 `default:"0.1"`

	// minimum total activity of all the units representing a value: when computing weighted average value, this is used as a minimum for the sum that you divide by
	MinSum float32 `default:"0.2"`
}

popcode.TwoD provides encoding and decoding of population codes, used to represent two continuous (scalar) values across a 2D tensor, using row-major XY encoding: Y = outer, first dim, X = inner, second dim

func (*TwoD) Decode

func (pc *TwoD) Decode(pat etensor.Tensor) (math32.Vector2, error)

Decode decodes 2D value from a pattern of activation as the activation-weighted-average of the unit's preferred tuning values.

func (*TwoD) DecodeImpl

func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (math32.Vector2, error)

DecodeImpl does direct decoding of x, y simultaneously -- for non-wrap

func (*TwoD) DecodeNPeaks

func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vector2, error)

DecodeNPeaks decodes N values from a pattern of activation using a neighborhood of specified width around local maxima, which is the amount on either side of the central point to accumulate (0 = localist, single points, 1 = +/- 1 points on either side in a square around central point, etc) Allocates a temporary slice of size pat, and sorts that: relatively expensive

func (*TwoD) Defaults

func (pc *TwoD) Defaults()

func (*TwoD) Encode

func (pc *TwoD) Encode(pat etensor.Tensor, val math32.Vector2, add bool) error

Encode generates a pattern of activation on given tensor, which must already have appropriate 2D shape which is used for encoding sizes (error if not). If add == false (use Set const for clarity), values are set to pattern else if add == true (Add), then values are added to any existing, for encoding additional values in same pattern.

func (*TwoD) EncodeImpl

func (pc *TwoD) EncodeImpl(pat etensor.Tensor, val math32.Vector2, add bool) error

EncodeImpl is the implementation of encoding -- e.g., used twice for Wrap

func (*TwoD) SetRange

func (pc *TwoD) SetRange(min, max, sigma float32)

SetRange sets the min, max and sigma values to the same scalar values

func (*TwoD) ShouldShow

func (pc *TwoD) ShouldShow(field string) bool

func (*TwoD) Values

func (pc *TwoD) Values(valsX, valsY *[]float32, nx, ny int)

Values sets the vals slices to the target preferred tuning values for each unit, for a distribution of given dimensions. n's must be 2 or more in each dim. vals slice will be constructed if len != n

Jump to

Keyboard shortcuts

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