popcode

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: BSD-3-Clause Imports: 6 Imported by: 30

README

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 {
	Code   PopCodes `desc:"how to encode the value"`
	Min    float32  `` /* 168-byte string literal not displayed */
	Max    float32  `` /* 168-byte string literal not displayed */
	Sigma  float32  `` /* 149-byte string literal not displayed */
	Clip   bool     `desc:"ensure that encoded and decoded value remains within specified range"`
	Thr    float32  `` /* 201-byte string literal not displayed */
	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
	LowVec  []float32 `view:"-" desc:"low-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. must have 2 or more values in pattern pat.

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 {
	Code   PopCodes   `desc:"how to encode the value"`
	Min    mat32.Vec2 `` /* 180-byte string literal not displayed */
	Max    mat32.Vec2 `` /* 180-byte string literal not displayed */
	Sigma  mat32.Vec2 `` /* 150-byte string literal not displayed */
	Clip   bool       `desc:"ensure that encoded and decoded value remains within specified range"`
	Thr    float32    `` /* 201-byte string literal not displayed */
	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 population of units / neurons (2 dimensional)

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