popcode

package
v1.4.31 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: BSD-3-Clause Imports: 5 Imported by: 30

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 `desc:"how to encode the value"`

	// 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 `` /* 168-byte string literal not displayed */

	// 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 `` /* 168-byte string literal not displayed */

	// [def: 0.2] [viewif: Code=GaussBump] sigma parameter of a gaussian specifying the tuning width of the coarse-coded units, in normalized 0-1 range
	Sigma float32 `` /* 149-byte string literal not displayed */

	// ensure that encoded and decoded value remains within specified range
	Clip bool `desc:"ensure that encoded and decoded value remains within specified range"`

	// [def: 0.1] 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 `` /* 215-byte string literal not displayed */

	// [def: 0.2] 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 `` /* 174-byte string literal not displayed */
}

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 added in v1.1.3

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 added in v1.0.0

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

SetRange sets the min, max and sigma values

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 added in v1.1.1

type Ring struct {
	OneD

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

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

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.0.0

type TwoD struct {

	// how to encode the value
	Code PopCodes `desc:"how to encode the value"`

	// 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 mat32.Vec2 `` /* 180-byte string literal not displayed */

	// 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 mat32.Vec2 `` /* 180-byte string literal not displayed */

	// [def: 0.2] [viewif: Code=GaussBump] sigma parameters of a gaussian specifying the tuning width of the coarse-coded units, in normalized 0-1 range
	Sigma mat32.Vec2 `` /* 150-byte string literal not displayed */

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

	// 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 `` /* 131-byte string literal not displayed */

	// 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 `` /* 131-byte string literal not displayed */

	// [def: 0.1] 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 `` /* 201-byte string literal not displayed */

	// [def: 0.2] 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 `` /* 174-byte string literal not displayed */
}

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 added in v1.0.0

func (pc *TwoD) Decode(pat etensor.Tensor) (mat32.Vec2, 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 added in v1.1.35

func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (mat32.Vec2, error)

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

func (*TwoD) DecodeNPeaks added in v1.1.3

func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]mat32.Vec2, 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 added in v1.0.0

func (pc *TwoD) Defaults()

func (*TwoD) Encode added in v1.0.0

func (pc *TwoD) Encode(pat etensor.Tensor, val mat32.Vec2, 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 added in v1.1.35

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

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

func (*TwoD) SetRange added in v1.0.0

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

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

func (*TwoD) Values added in v1.0.0

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