Documentation ¶
Overview ¶
Package prjn is a separate package for defining patterns of connectivity between layers (i.e., the ProjectionSpecs from C++ emergent). This is done using a fully independent structure that *only* knows about the shapes of the two layers, and it returns a fully general bitmap representation of the pattern of connectivity between them.
The algorithm-specific leabra.Prjn code then uses these patterns to do all the nitty-gritty of connecting up neurons.
This makes the projection code *much* simpler compared to the ProjectionSpec in C++ emergent, which was involved in both creating the pattern and also all the complexity of setting up the actual connections themselves. This should be the *last* time any of those projection patterns need to be written (having re-written this code too many times in the C++ version as the details of memory allocations changed).
A Pattern maintains nothing about a specific projection -- it only has the parameters that are applied in creating a new pattern of connectivity, so it can be shared among any number of projections that need the same connectivity parameters.
All Patttern types have a New<Name> where <Name> is the type name, that creates a new instance of given pattern initialized with default values.
Individual Pattern types may have a Defaults() method to initialize default values, but it is not mandatory.
Also, the Edge method is handy for dealing with edges and wrap-around etc.
Index ¶
- func ConsStringFull(send, recv *etensor.Shape, cons *etensor.Bits) []byte
- func ConsStringPerRecv(send, recv *etensor.Shape, cons *etensor.Bits) []byte
- func Edge(ci, max int, wrap bool) (int, bool)
- func NewTensors(send, recv *etensor.Shape) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func WrapMinDist(ci, max, ctr float32) float32
- type Circle
- type Full
- type GaussTopo
- type OneToOne
- type Pattern
- type PoolOneToOne
- func (ot *PoolOneToOne) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolOneToOne) ConnectOneToOne(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolOneToOne) ConnectPools(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolOneToOne) ConnectRecvPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolOneToOne) ConnectSendPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolOneToOne) Name() string
- type PoolRect
- type PoolSameUnit
- func (ot *PoolSameUnit) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolSameUnit) ConnectOneToOne(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolSameUnit) ConnectPools(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolSameUnit) ConnectRecvPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolSameUnit) ConnectSendPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ot *PoolSameUnit) Name() string
- type PoolTile
- func (pt *PoolTile) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (pt *PoolTile) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (pt *PoolTile) Defaults()
- func (pt *PoolTile) GaussOff()
- func (pt *PoolTile) Name() string
- func (pt *PoolTile) TopoWts(send, recv *etensor.Shape, wts *etensor.Float32) error
- func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float32) error
- func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float32) error
- func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Float32) error
- func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Float32) error
- type PoolUnifRnd
- func (ur *PoolUnifRnd) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *PoolUnifRnd) ConnectPoolsRnd(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *PoolUnifRnd) ConnectRnd(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *PoolUnifRnd) Name() string
- type Rect
- type SigmoidTopo
- type UnifRnd
- func (ur *UnifRnd) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *UnifRnd) ConnectFull(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *UnifRnd) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
- func (ur *UnifRnd) Name() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsStringFull ¶
ConsStringFull returns a []byte string showing the pattern of connectivity. if perRecv is true then it displays the sending connections per each recv unit -- otherwise it shows the entire matrix as a 2D matrix
func ConsStringPerRecv ¶
ConsStringPerRecv returns a []byte string showing the pattern of connectivity organized by receiving unit, showing the sending connections per each
func Edge ¶ added in v1.0.0
Edge returns coordinate value based on either wrapping or clipping at the edge and if not wrapping, if it should be clipped (ignored)
func NewTensors ¶
NewTensors returns the tensors used for Connect method, based on layer sizes
func WrapMinDist ¶ added in v1.0.0
WrapMinDist returns the wrapped coordinate value that is closest to ctr i.e., if going out beyond max is closer, then returns that coordinate else if going below 0 is closer than not, then returns that coord
Types ¶
type Circle ¶ added in v1.0.0
type Circle struct { Radius int `desc:"radius of the circle, in units from center in sending layer"` Start evec.Vec2i `desc:"starting offset in sending layer, for computing the corresponding sending center relative to given recv unit position"` Scale mat32.Vec2 `desc:"scaling to apply to receiving unit position to compute sending center as function of recv unit position"` AutoScale bool `` /* 178-byte string literal not displayed */ Wrap bool `desc:"if true, connectivity wraps around edges"` Sigma float32 `desc:"gaussian sigma (width) as a proportion of the radius of the circle"` MaxWt float32 `desc:"maximum weight value for GaussWts function -- multiplies values"` SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"` }
Circle implements a circular pattern of connectivity between two layers where the center moves in proportion to receiver position with offset and multiplier factors, and a given radius is used (with wrap-around optionally). A corresponding Gaussian bump of TopoWts is available as well. Makes for a good center-surround connectivity pattern. 4D layers are automatically flattened to 2D for this connection.
type Full ¶
type Full struct {
SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"`
}
Full implements full all-to-all pattern of connectivity between two layers
type GaussTopo ¶ added in v1.0.0
type GaussTopo struct { On bool `desc:"use gaussian topographic weights / scaling values"` Sigma float32 `` /* 189-byte string literal not displayed */ Wrap bool `` /* 258-byte string literal not displayed */ CtrMove float32 `` /* 251-byte string literal not displayed */ }
GaussTopo has parameters for Gaussian topographic weights or scaling factors
func (*GaussTopo) DefNoWrap ¶ added in v1.0.0
func (gt *GaussTopo) DefNoWrap()
DefNoWrap sets default no-wrap parameters (CtrMove = .8 instead of 1)
type OneToOne ¶
type OneToOne struct { NCons int `desc:"number of recv connections to make (0 for entire size of recv layer)"` SendStart int `desc:"starting unit index for sending connections"` RecvStart int `desc:"starting unit index for recv connections"` }
OneToOne implements point-to-point one-to-one pattern of connectivity between two layers
func NewOneToOne ¶
func NewOneToOne() *OneToOne
type Pattern ¶
type Pattern interface { // Name returns the name of the pattern -- i.e., the "type" name of the actual pattern generatop Name() string // Connect connects layers with the given shapes, returning the pattern of connectivity // as a bits tensor with shape = recv + send shapes, using row-major ordering with outer-most // indexes first (i.e., for each recv unit, there is a full inner-level of sender bits). // The number of connections for each recv and each send unit are also returned in // recvn and send tensors, each the shape of send and recv respectively. // The same flag should be set to true if the send and recv layers are the same (i.e., a self-connection) // often there are some different options for such connections. Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits) }
Pattern defines a pattern of connectivity between two layers. The pattern is stored efficiently using a bitslice tensor of binary values indicating presence or absence of connection between two items. A receiver-based organization is generally assumed but connectivity can go either way.
type PoolOneToOne ¶
type PoolOneToOne struct { NPools int `desc:"number of recv pools to connect (0 for entire number of pools in recv layer)"` SendStart int `desc:"starting pool index for sending connections"` RecvStart int `desc:"starting pool index for recv connections"` }
PoolOneToOne implements one-to-one connectivity between pools within layers. Pools are the outer-most two dimensions of a 4D layer shape. If either layer does not have pools, then if the number of individual units matches the number of pools in the other layer, those are connected one-to-one otherwise each pool connects to the entire set of other units. If neither is 4D, then it is equivalent to OneToOne.
func NewPoolOneToOne ¶
func NewPoolOneToOne() *PoolOneToOne
func (*PoolOneToOne) ConnectOneToOne ¶
func (ot *PoolOneToOne) ConnectOneToOne(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
copy of OneToOne.Connect
func (*PoolOneToOne) ConnectPools ¶
func (ot *PoolOneToOne) ConnectPools(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectPools is when both recv and send have pools
func (*PoolOneToOne) ConnectRecvPool ¶
func (ot *PoolOneToOne) ConnectRecvPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectRecvPool is when recv has pools but send doesn't
func (*PoolOneToOne) ConnectSendPool ¶
func (ot *PoolOneToOne) ConnectSendPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectSendPool is when send has pools but recv doesn't
func (*PoolOneToOne) Name ¶
func (ot *PoolOneToOne) Name() string
type PoolRect ¶ added in v1.1.8
type PoolRect struct { Size evec.Vec2i `desc:"size of rectangle (of pools) in sending layer that each receiving unit receives from"` Start evec.Vec2i `` /* 140-byte string literal not displayed */ Scale mat32.Vec2 `` /* 138-byte string literal not displayed */ AutoScale bool `` /* 152-byte string literal not displayed */ RoundScale bool `` /* 197-byte string literal not displayed */ Wrap bool `desc:"if true, connectivity wraps around all edges if it would otherwise go off the edge -- if false, then edges are clipped"` SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"` RecvStart evec.Vec2i `desc:"starting pool position in receiving layer -- if > 0 then pools below this starting point remain unconnected"` RecvN evec.Vec2i `` /* 187-byte string literal not displayed */ }
PoolRect implements a rectangular pattern of connectivity between two 4D layers, in terms of their pool-level shapes, where the lower-left corner moves in proportion to receiver pool position with offset and multiplier factors (with wrap-around optionally).
func NewPoolRect ¶ added in v1.1.8
func NewPoolRect() *PoolRect
type PoolSameUnit ¶ added in v1.1.7
type PoolSameUnit struct {
SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"`
}
PoolSameUnit connects a given unit to the unit at the same index across all the pools in a layer. Pools are the outer-most two dimensions of a 4D layer shape. This is most sensible when pools have same numbers of units in send and recv. This is typically used for lateral topography-inducing connectivity and can also serve to reduce a pooled layer down to a single pool. The logic works if either layer does not have pools. If neither is 4D, then it is equivalent to OneToOne.
func NewPoolSameUnit ¶ added in v1.1.7
func NewPoolSameUnit() *PoolSameUnit
func (*PoolSameUnit) ConnectOneToOne ¶ added in v1.1.7
func (ot *PoolSameUnit) ConnectOneToOne(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
copy of OneToOne.Connect
func (*PoolSameUnit) ConnectPools ¶ added in v1.1.7
func (ot *PoolSameUnit) ConnectPools(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectPools is when both recv and send have pools
func (*PoolSameUnit) ConnectRecvPool ¶ added in v1.1.7
func (ot *PoolSameUnit) ConnectRecvPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectRecvPool is when recv has pools but send doesn't
func (*PoolSameUnit) ConnectSendPool ¶ added in v1.1.7
func (ot *PoolSameUnit) ConnectSendPool(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectSendPool is when send has pools but recv doesn't
func (*PoolSameUnit) Name ¶ added in v1.1.7
func (ot *PoolSameUnit) Name() string
type PoolTile ¶ added in v1.0.0
type PoolTile struct { Recip bool `` /* 165-byte string literal not displayed */ Size evec.Vec2i `desc:"size of receptive field tile, in terms of pools on the sending layer"` Skip evec.Vec2i `desc:"how many pools to skip in tiling over sending layer -- typically 1/2 of Size"` Start evec.Vec2i `desc:"starting pool offset for lower-left corner of first receptive field in sending layer"` Wrap bool `` /* 142-byte string literal not displayed */ GaussFull GaussTopo `desc:"gaussian topographic weights / scaling parameters for full receptive field width. multiplies any other factors present"` GaussInPool GaussTopo `` /* 305-byte string literal not displayed */ SigFull SigmoidTopo `` /* 241-byte string literal not displayed */ SigInPool SigmoidTopo `` /* 421-byte string literal not displayed */ TopoRange minmax.F32 `desc:"min..max range of topographic weight values to generate "` }
PoolTile implements tiled 2D connectivity between pools within layers, where a 2D rectangular receptive field (defined over pools, not units) is tiled across the sending layer pools, with specified level of overlap. Pools are the outer-most two dimensions of a 4D layer shape, and both layers must have pools. This is a standard form of convolutional connectivity, where pools are the filters and the outer dims are locations filtered. Various initial weight / scaling patterns are also available -- code must specifically apply these to the receptive fields.
func NewPoolTile ¶ added in v1.0.0
func NewPoolTile() *PoolTile
func NewPoolTileRecip ¶ added in v1.0.0
NewPoolTileRecip creates a new PoolTile that is a recip version of given ff feedforward one
func (*PoolTile) ConnectRecip ¶ added in v1.0.0
func (*PoolTile) GaussOff ¶ added in v1.1.4
func (pt *PoolTile) GaussOff()
GaussOff turns off gaussian weights
func (*PoolTile) TopoWts ¶ added in v1.0.0
TopoWts sets values in given 4D or 6D tensor according to *Topo settings. wts is shaped with first 2 outer-most dims as Y, X of units within layer / pool of recv layer (these are units over which topography is defined) and remaing 2D or 4D is for receptive field Size by units within pool size for sending layer.
func (*PoolTile) TopoWtsGauss2D ¶ added in v1.1.4
TopoWtsGauss2D sets values in given 4D tensor according to *Topo settings. wts is shaped with first 2 outer-most dims as Y, X of units within layer / pool of recv layer (these are units over which topography is defined) and remaing 2D is for sending layer size (2D = sender)
func (*PoolTile) TopoWtsGauss4D ¶ added in v1.1.4
TopoWtsGauss4D sets values in given 6D tensor according to *Topo settings. wts is shaped with first 2 outer-most dims as Y, X of units within layer / pool of recv layer (these are units over which topography is defined) and remaing 4D is for receptive field Size by units within pool size for sending layer.
func (*PoolTile) TopoWtsSigmoid2D ¶ added in v1.1.4
TopoWtsSigmoid2D sets values in given 4D tensor according to Topo settings. wts is shaped with first 2 outer-most dims as Y, X of units within pool of recv layer (these are units over which topography is defined) and remaing 2D is for sending layer (2D = sender).
func (*PoolTile) TopoWtsSigmoid4D ¶ added in v1.1.4
TopoWtsSigmoid4D sets values in given 6D tensor according to Topo settings. wts is shaped with first 2 outer-most dims as Y, X of units within pool of recv layer (these are units over which topography is defined) and remaing 2D is for receptive field Size by units within pool size for sending layer.
type PoolUnifRnd ¶ added in v1.0.7
type PoolUnifRnd struct { PoolOneToOne UnifRnd }
PoolUnifRnd implements random pattern of connectivity between pools within layers. Pools are the outer-most two dimensions of a 4D layer shape. If either layer does not have pools, PoolUnifRnd works as UnifRnd does. If probability of connection (PCon) is 1, PoolUnifRnd works as PoolOnetoOne does.
func NewPoolUnifRnd ¶ added in v1.0.7
func NewPoolUnifRnd() *PoolUnifRnd
func (*PoolUnifRnd) ConnectPoolsRnd ¶ added in v1.0.7
func (ur *PoolUnifRnd) ConnectPoolsRnd(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectPoolsRnd is when both recv and send have pools
func (*PoolUnifRnd) ConnectRnd ¶ added in v1.0.7
func (ur *PoolUnifRnd) ConnectRnd(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)
ConnectRnd is a copy of UnifRnd.Connect with initial if statement modified
func (*PoolUnifRnd) Name ¶ added in v1.0.7
func (ur *PoolUnifRnd) Name() string
type Rect ¶ added in v1.0.0
type Rect struct { Size evec.Vec2i `desc:"size of rectangle in sending layer that each receiving unit receives from"` Start evec.Vec2i `` /* 135-byte string literal not displayed */ Scale mat32.Vec2 `` /* 139-byte string literal not displayed */ AutoScale bool `` /* 147-byte string literal not displayed */ RoundScale bool `` /* 197-byte string literal not displayed */ Wrap bool `desc:"if true, connectivity wraps around all edges if it would otherwise go off the edge -- if false, then edges are clipped"` SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"` RecvStart evec.Vec2i `desc:"starting position in receiving layer -- if > 0 then units below this starting point remain unconnected"` RecvN evec.Vec2i `` /* 187-byte string literal not displayed */ }
Rect implements a rectangular pattern of connectivity between two layers where the lower-left corner moves in proportion to receiver position with offset and multiplier factors (with wrap-around optionally). 4D layers are automatically flattened to 2D for this projection.
type SigmoidTopo ¶ added in v1.1.4
type SigmoidTopo struct { On bool `desc:"use gaussian topographic weights / scaling values"` Gain float32 `` /* 193-byte string literal not displayed */ CtrMove float32 `` /* 251-byte string literal not displayed */ }
SigmoidTopo has parameters for Gaussian topographic weights or scaling factors
func (*SigmoidTopo) Defaults ¶ added in v1.1.4
func (gt *SigmoidTopo) Defaults()
type UnifRnd ¶ added in v1.0.0
type UnifRnd struct { PCon float32 `min:"0" max:"1" desc:"probability of connection (0-1)"` RndSeed int64 `view:"-" desc:"the current random seed"` SelfCon bool `desc:"if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself"` Recip bool `` /* 192-byte string literal not displayed */ }
UnifRnd implements uniform random pattern of connectivity between two layers uses a permuted (shuffled) list for without-replacement randomness and maintains its own local random seed for fully replicable results (if seed is not set when run, then random number generator is used to create seed) should reset seed after calling to resume sequence appropriately
func NewUnifRnd ¶ added in v1.0.0
func NewUnifRnd() *UnifRnd