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
- type OneD
- func (pc *OneD) Decode(pat []float32) float32
- func (pc *OneD) DecodeNPeaks(pat []float32, nvals, width int) []float32
- func (pc *OneD) Defaults()
- func (pc *OneD) Encode(pat *[]float32, val float32, n int, add bool)
- func (pc *OneD) SetRange(min, max, sigma float32)
- func (pc *OneD) Values(vals *[]float32, n int)
- type PopCodes
- type Ring
- type TwoD
- func (pc *TwoD) Decode(pat etensor.Tensor) (mat32.Vec2, error)
- func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (mat32.Vec2, error)
- func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]mat32.Vec2, error)
- func (pc *TwoD) Defaults()
- func (pc *TwoD) Encode(pat etensor.Tensor, val mat32.Vec2, add bool) error
- func (pc *TwoD) EncodeImpl(pat etensor.Tensor, val mat32.Vec2, add bool) error
- func (pc *TwoD) SetRange(min, max, sigma float32)
- func (pc *TwoD) Values(valsX, valsY *[]float32, nx, ny int)
Constants ¶
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 ¶
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
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) Encode ¶
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.
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
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
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
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
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
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
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
DecodeImpl does direct decoding of x, y simultaneously -- for non-wrap
func (*TwoD) DecodeNPeaks ¶ added in v1.1.3
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) Encode ¶ added in v1.0.0
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
EncodeImpl is the implementation of encoding -- e.g., used twice for Wrap