prjn

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: 13 Imported by: 20

README

Docs: GoDoc

See Wiki Params page for detailed docs.

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 where 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.

Topographic Weights

Some projections (e.g., Circle, PoolTile) support the generation of topographic weight patterns that can be used to set initial weights, or per-synapse scaling factors. The Pattern interface does not define any standard for how this done, as there are various possible approaches. Circle defines a method with a standard signature that can be called for each point in the pattern, while PoolTile has a lot more overhead per point and is thus more efficient to generate the whole set of weights to tensor, which can then be used.

It is recommended to have some kind of positive flag(s) for enabling the use of TopoWts -- the standard weight initialization methods, e.g., leabra.Network.InitWts, can then automatically do the correct thing for each type of standard projection -- custom ones outside of this standard set would need custom code..

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsStringFull

func ConsStringFull(send, recv *etensor.Shape, cons *etensor.Bits) []byte

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

func ConsStringPerRecv(send, recv *etensor.Shape, cons *etensor.Bits) []byte

ConsStringPerRecv returns a []byte string showing the pattern of connectivity organized by receiving unit, showing the sending connections per each

func NewTensors

func NewTensors(send, recv *etensor.Shape) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

NewTensors returns the tensors used for Connect method, based on layer sizes

Types

type Circle

type Circle struct {

	// radius of the circle, in units from center in sending layer
	Radius int

	// starting offset in sending layer, for computing the corresponding sending center relative to given recv unit position
	Start evec.Vector2i

	// scaling to apply to receiving unit position to compute sending center as function of recv unit position
	Scale math32.Vector2

	// auto-scale sending center positions as function of relative sizes of send and recv layers -- if Start is positive then assumes it is a border, subtracted from sending size
	AutoScale bool

	// if true, connectivity wraps around edges
	Wrap bool

	// if true, this prjn should set gaussian topographic weights, according to following parameters
	TopoWts bool

	// gaussian sigma (width) as a proportion of the radius of the circle
	Sigma float32

	// maximum weight value for GaussWts function -- multiplies values
	MaxWt float32

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool
}

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.

func NewCircle

func NewCircle() *Circle

func (*Circle) Connect

func (cr *Circle) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*Circle) Defaults

func (cr *Circle) Defaults()

func (*Circle) GaussWts

func (cr *Circle) GaussWts(si, ri int, send, recv *etensor.Shape) float32

GaussWts returns gaussian weight value for given unit indexes in given send and recv layers according to Gaussian Sigma and MaxWt. Can be used for a Prjn.SetScalesFunc or SetWtsFunc

func (*Circle) Name

func (cr *Circle) Name() string

type Full

type Full struct {

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool
}

Full implements full all-to-all pattern of connectivity between two layers

func NewFull

func NewFull() *Full

func (*Full) Connect

func (fp *Full) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*Full) Name

func (fp *Full) Name() string

type GaussTopo

type GaussTopo struct {

	// use gaussian topographic weights / scaling values
	On bool

	// gaussian sigma (width) in normalized units where entire distance across relevant dimension is 1.0 -- typical useful values range from .3 to 1.5, with .6 default
	Sigma float32 `default:"0.6"`

	// wrap the gaussian around on other sides of the receptive field, with the closest distance being used -- this removes strict topography but ensures a more uniform distribution of weight values so edge units don't have weaker overall weights
	Wrap bool

	// proportion to move gaussian center relative to the position of the receiving unit within its pool: 1.0 = centers span the entire range of the receptive field.  Typically want to use 1.0 for Wrap = true, and 0.8 for false
	CtrMove float32 `default:"0.8,1"`
}

GaussTopo has parameters for Gaussian topographic weights or scaling factors

func (*GaussTopo) DefNoWrap

func (gt *GaussTopo) DefNoWrap()

DefNoWrap sets default no-wrap parameters (CtrMove = .8 instead of 1)

func (*GaussTopo) DefWrap

func (gt *GaussTopo) DefWrap()

DefWrap sets default wrap parameters (which are overall defaults): CtrMove = 1

func (*GaussTopo) Defaults

func (gt *GaussTopo) Defaults()

func (*GaussTopo) ShouldShow

func (gt *GaussTopo) ShouldShow(field string) bool

type OneToOne

type OneToOne struct {

	// number of recv connections to make (0 for entire size of recv layer)
	NCons int

	// starting unit index for sending connections
	SendStart int

	// starting unit index for recv connections
	RecvStart int
}

OneToOne implements point-to-point one-to-one pattern of connectivity between two layers

func NewOneToOne

func NewOneToOne() *OneToOne

func (*OneToOne) Connect

func (ot *OneToOne) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*OneToOne) Name

func (ot *OneToOne) Name() string

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 {

	// number of recv pools to connect (0 for entire number of pools in recv layer)
	NPools int

	// starting pool index for sending connections
	SendStart int

	// starting pool index for recv connections
	RecvStart int
}

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

func (ot *PoolOneToOne) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

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

type PoolRect struct {

	// size of rectangle (of pools) in sending layer that each receiving unit receives from
	Size evec.Vector2i

	// starting pool offset in sending layer, for computing the corresponding sending lower-left corner relative to given recv pool position
	Start evec.Vector2i

	// scaling to apply to receiving pool osition to compute corresponding position in sending layer of the lower-left corner of rectangle
	Scale math32.Vector2

	// auto-set the Scale as function of the relative pool sizes of send and recv layers (e.g., if sending layer is 2x larger than receiving, Scale = 2)
	AutoScale bool

	// if true, use Round when applying scaling factor -- otherwise uses Floor which makes Scale work like a grouping factor -- e.g., .25 will effectively group 4 recv pools with same send position
	RoundScale bool

	// if true, connectivity wraps around all edges if it would otherwise go off the edge -- if false, then edges are clipped
	Wrap bool

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool

	// starting pool position in receiving layer -- if > 0 then pools below this starting point remain unconnected
	RecvStart evec.Vector2i

	// number of pools in receiving layer to connect -- if 0 then all (remaining after RecvStart) are connected -- otherwise if < remaining then those beyond this point remain unconnected
	RecvN evec.Vector2i
}

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

func NewPoolRect() *PoolRect

func (*PoolRect) Connect

func (cr *PoolRect) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolRect) Defaults

func (cr *PoolRect) Defaults()

func (*PoolRect) Name

func (cr *PoolRect) Name() string

type PoolSameUnit

type PoolSameUnit struct {

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool
}

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

func NewPoolSameUnit() *PoolSameUnit

func (*PoolSameUnit) Connect

func (ot *PoolSameUnit) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolSameUnit) ConnectOneToOne

func (ot *PoolSameUnit) ConnectOneToOne(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

copy of OneToOne.Connect

func (*PoolSameUnit) ConnectPools

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

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

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

func (ot *PoolSameUnit) Name() string

type PoolTile

type PoolTile struct {

	// reciprocal topographic connectivity -- logic runs with recv <-> send -- produces symmetric back-projection or topo prjn when sending layer is larger than recv
	Recip bool

	// size of receptive field tile, in terms of pools on the sending layer
	Size evec.Vector2i

	// how many pools to skip in tiling over sending layer -- typically 1/2 of Size
	Skip evec.Vector2i

	// starting pool offset for lower-left corner of first receptive field in sending layer
	Start evec.Vector2i

	// if true, pool coordinates wrap around sending shape -- otherwise truncated at edges, which can lead to assymmetries in connectivity etc
	Wrap bool

	// gaussian topographic weights / scaling parameters for full receptive field width. multiplies any other factors present
	GaussFull GaussTopo

	// gaussian topographic weights / scaling parameters within individual sending pools (i.e., unit positions within their parent pool drive distance for gaussian) -- this helps organize / differentiate units more within pools, not just across entire receptive field. multiplies any other factors present
	GaussInPool GaussTopo

	// sigmoidal topographic weights / scaling parameters for full receptive field width.  left / bottom half have increasing sigmoids, and second half decrease.  Multiplies any other factors present (only used if Gauss versions are not On!)
	SigFull SigmoidTopo

	// sigmoidal topographic weights / scaling parameters within individual sending pools (i.e., unit positions within their parent pool drive distance for sigmoid) -- this helps organize / differentiate units more within pools, not just across entire receptive field. multiplies any other factors present  (only used if Gauss versions are not On!).  left / bottom half have increasing sigmoids, and second half decrease.
	SigInPool SigmoidTopo

	// min..max range of topographic weight values to generate
	TopoRange minmax.F32
}

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. 2D layers are assumed to have 1x1 pool. 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

func NewPoolTile() *PoolTile

func NewPoolTileRecip

func NewPoolTileRecip(ff *PoolTile) *PoolTile

NewPoolTileRecip creates a new PoolTile that is a recip version of given ff feedforward one

func (*PoolTile) Connect

func (pt *PoolTile) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolTile) ConnectRecip

func (pt *PoolTile) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolTile) Defaults

func (pt *PoolTile) Defaults()

func (*PoolTile) GaussOff

func (pt *PoolTile) GaussOff()

GaussOff turns off gaussian weights

func (*PoolTile) HasTopoWts

func (pt *PoolTile) HasTopoWts() bool

HasTopoWts returns true if some form of topographic weight patterns are set

func (*PoolTile) Name

func (pt *PoolTile) Name() string

func (*PoolTile) TopoWts

func (pt *PoolTile) TopoWts(send, recv *etensor.Shape, wts *etensor.Float32) error

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

func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float32) error

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

func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float32) error

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

func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Float32) error

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

func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Float32) error

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 PoolTileSub

type PoolTileSub struct {

	// reciprocal topographic connectivity -- logic runs with recv <-> send -- produces symmetric back-projection or topo prjn when sending layer is larger than recv
	Recip bool

	// size of receptive field tile, in terms of pools on the sending layer
	Size evec.Vector2i

	// how many pools to skip in tiling over sending layer -- typically 1/2 of Size
	Skip evec.Vector2i

	// starting pool offset for lower-left corner of first receptive field in sending layer
	Start evec.Vector2i

	// number of sub-pools within each pool
	Subs evec.Vector2i

	// sending layer has sub-pools
	SendSubs bool

	// if true, pool coordinates wrap around sending shape -- otherwise truncated at edges, which can lead to assymmetries in connectivity etc
	Wrap bool

	// gaussian topographic weights / scaling parameters for full receptive field width. multiplies any other factors present
	GaussFull GaussTopo

	// gaussian topographic weights / scaling parameters within individual sending pools (i.e., unit positions within their parent pool drive distance for gaussian) -- this helps organize / differentiate units more within pools, not just across entire receptive field. multiplies any other factors present
	GaussInPool GaussTopo

	// sigmoidal topographic weights / scaling parameters for full receptive field width.  left / bottom half have increasing sigmoids, and second half decrease.  Multiplies any other factors present (only used if Gauss versions are not On!)
	SigFull SigmoidTopo

	// sigmoidal topographic weights / scaling parameters within individual sending pools (i.e., unit positions within their parent pool drive distance for sigmoid) -- this helps organize / differentiate units more within pools, not just across entire receptive field. multiplies any other factors present  (only used if Gauss versions are not On!).  left / bottom half have increasing sigmoids, and second half decrease.
	SigInPool SigmoidTopo

	// min..max range of topographic weight values to generate
	TopoRange minmax.F32
}

PoolTileSub 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. Sub version has sub-pools within each pool to encourage more independent representations. 2D layers are assumed to have 1x1 pool. 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 NewPoolTileSub

func NewPoolTileSub() *PoolTileSub

func NewPoolTileSubRecip

func NewPoolTileSubRecip(ff *PoolTileSub) *PoolTileSub

NewPoolTileSubRecip creates a new PoolTileSub that is a recip version of given ff feedforward one

func (*PoolTileSub) Connect

func (pt *PoolTileSub) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolTileSub) ConnectRecip

func (pt *PoolTileSub) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolTileSub) Defaults

func (pt *PoolTileSub) Defaults()

func (*PoolTileSub) GaussOff

func (pt *PoolTileSub) GaussOff()

GaussOff turns off gaussian weights

func (*PoolTileSub) HasTopoWts

func (pt *PoolTileSub) HasTopoWts() bool

HasTopoWts returns true if some form of topographic weight patterns are set

func (*PoolTileSub) Name

func (pt *PoolTileSub) Name() string

func (*PoolTileSub) TopoWts

func (pt *PoolTileSub) TopoWts(send, recv *etensor.Shape, wts *etensor.Float32) error

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 (*PoolTileSub) TopoWtsGauss2D

func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float32) error

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 (*PoolTileSub) TopoWtsGauss4D

func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float32) error

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 (*PoolTileSub) TopoWtsSigmoid2D

func (pt *PoolTileSub) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Float32) error

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 (*PoolTileSub) TopoWtsSigmoid4D

func (pt *PoolTileSub) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Float32) error

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

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

func NewPoolUnifRnd() *PoolUnifRnd

func (*PoolUnifRnd) Connect

func (ur *PoolUnifRnd) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*PoolUnifRnd) ConnectPoolsRnd

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

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

func (ur *PoolUnifRnd) Name() string

type Rect

type Rect struct {

	// size of rectangle in sending layer that each receiving unit receives from
	Size evec.Vector2i

	// starting offset in sending layer, for computing the corresponding sending lower-left corner relative to given recv unit position
	Start evec.Vector2i

	// scaling to apply to receiving unit position to compute corresponding position in sending layer of the lower-left corner of rectangle
	Scale math32.Vector2

	// auto-set the Scale as function of the relative sizes of send and recv layers (e.g., if sending layer is 2x larger than receiving, Scale = 2)
	AutoScale bool

	// if true, use Round when applying scaling factor -- otherwise uses Floor which makes Scale work like a grouping factor -- e.g., .25 will effectively group 4 recv units with same send position
	RoundScale bool

	// if true, connectivity wraps around all edges if it would otherwise go off the edge -- if false, then edges are clipped
	Wrap bool

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool

	// make the reciprocal of the specified connections -- i.e., symmetric for swapping recv and send
	Recip bool

	// starting position in receiving layer -- if > 0 then units below this starting point remain unconnected
	RecvStart evec.Vector2i

	// number of units in receiving layer to connect -- if 0 then all (remaining after RecvStart) are connected -- otherwise if < remaining then those beyond this point remain unconnected
	RecvN evec.Vector2i
}

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.

func NewRect

func NewRect() *Rect

func NewRectRecip

func NewRectRecip(ff *Rect) *Rect

NewRectRecip creates a new Rect that is a Recip version of given ff one

func (*Rect) Connect

func (cr *Rect) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*Rect) ConnectRecip

func (cr *Rect) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*Rect) Defaults

func (cr *Rect) Defaults()

func (*Rect) Name

func (cr *Rect) Name() string

type SigmoidTopo

type SigmoidTopo struct {

	// use gaussian topographic weights / scaling values
	On bool

	// gain of sigmoid that determines steepness of curve, in normalized units where entire distance across relevant dimension is 1.0 -- typical useful values range from 0.01 to 0.1
	Gain float32

	// proportion to move gaussian center relative to the position of the receiving unit within its pool: 1.0 = centers span the entire range of the receptive field.  Typically want to use 1.0 for Wrap = true, and 0.8 for false
	CtrMove float32 `default:"0.5,1"`
}

SigmoidTopo has parameters for Gaussian topographic weights or scaling factors

func (*SigmoidTopo) Defaults

func (gt *SigmoidTopo) Defaults()

func (*SigmoidTopo) ShouldShow

func (gt *SigmoidTopo) ShouldShow(field string) bool

type UnifRnd

type UnifRnd struct {

	// probability of connection (0-1)
	PCon float32 `min:"0" max:"1"`

	// if true, and connecting layer to itself (self projection), then make a self-connection from unit to itself
	SelfCon bool

	// reciprocal connectivity: if true, switch the sending and receiving layers to create a symmetric top-down projection -- ESSENTIAL to use same RndSeed between two prjns to ensure symmetry
	Recip bool

	// random number source -- is created with its own separate source if nil
	Rand erand.Rand `view:"-"`

	// the current random seed -- will be initialized to a new random number from the global random stream when Rand is created.
	RndSeed int64 `view:"-"`
}

UnifRnd implements uniform random pattern of connectivity between two layers using a permuted (shuffled) list for without-replacement randomness, and maintains its own local random number source and seed which are initialized if Rand == nil -- usually best to keep this specific to each instance of a projection so it is fully reproducible and doesn't interfere with other random number streams.

func NewUnifRnd

func NewUnifRnd() *UnifRnd

func (*UnifRnd) Connect

func (ur *UnifRnd) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*UnifRnd) ConnectFull

func (ur *UnifRnd) ConnectFull(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

func (*UnifRnd) ConnectRecip

func (ur *UnifRnd) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn *etensor.Int32, cons *etensor.Bits)

ConnectRecip does reciprocal connectvity

func (*UnifRnd) InitRand

func (ur *UnifRnd) InitRand()

func (*UnifRnd) Name

func (ur *UnifRnd) Name() string

Jump to

Keyboard shortcuts

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