emer

package
v2.0.0-dev0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: BSD-3-Clause Imports: 23 Imported by: 35

README

Docs: GoDoc

Package emer provides minimal interfaces for the basic structural elements of neural networks including:

  • emer.Network, emer.Layer, emer.Unit, emer.Path (pathway that interconnects layers)

These interfaces are intended to be just sufficient to support visualization and generic analysis kinds of functions, but explicitly avoid exposing ANY of the algorithmic aspects, so that those can be purely encoded in the implementation structs.

At this point, given the extra complexity it would require, these interfaces do not support the ability to build or modify networks.

Also added support for managing parameters in the emer.Params object, which handles standard parameter set logic and support for applying to networks, and the NetSize map for configuring network size.

Documentation

Overview

Package emer provides minimal interfaces for the basic structural elements of neural networks including: * emer.Network, emer.Layer, emer.Unit, emer.Path (pathway that interconnects layers)

These interfaces are intended to be just sufficient to support visualization and generic analysis kinds of functions, but explicitly avoid exposing ANY of the algorithmic aspects, so that those can be purely encoded in the implementation structs.

At this point, given the extra complexity it would require, these interfaces do not support the ability to build or modify networks.

Index

Constants

View Source
const (
	// AllParams can be used for ParamsString arg to list all params.
	AllParams = false

	// NonDefault can be used for ParamsString arg to list only non-default params.
	NonDefault = true
)

Variables

View Source
var (
	// LayerDimNames2D provides the standard Shape dimension names for 2D layers
	LayerDimNames2D = []string{"Y", "X"}

	// LayerDimNames4D provides the standard Shape dimension names for 4D layers
	// which have Pools and then neurons within pools.
	LayerDimNames4D = []string{"PoolY", "PoolX", "NeurY", "NeurX"}
)

Functions

func CenterPoolIndexes

func CenterPoolIndexes(ly Layer, n int) []int

CenterPoolIndexes returns the indexes for n x n center pools of given 4D layer. Useful for setting SampleIndexes on Layer. Will crash if called on non-4D layers.

func CenterPoolShape

func CenterPoolShape(ly Layer, n int) []int

CenterPoolShape returns shape for n x n center pools of given 4D layer. Useful for setting SampleShape on Layer.

func InitLayer

func InitLayer(l Layer, name string)

InitLayer initializes the layer, setting the EmerLayer interface to provide access to it for LayerBase methods, along with the name.

func InitNetwork

func InitNetwork(nt Network, name string)

InitNetwork initializes the network, setting the EmerNetwork interface to provide access to it for NetworkBase methods, along with the name.

func InitPath

func InitPath(pt Path)

InitPath initializes the path, setting the EmerPath interface to provide access to it for PathBase methods.

func Layer2DSampleIndexes

func Layer2DSampleIndexes(ly Layer, maxSize int) (idxs, shape []int)

Layer2DSampleIndexes returns neuron indexes and corresponding 2D shape for the representative neurons within a large 2D layer, for passing to [SetSampleShape]. These neurons are used for the raster plot in the GUI and for computing PCA, among other cases where the full set of neurons is problematic. The lower-left corner of neurons up to given maxSize is selected.

Types

type Layer

type Layer interface {

	// AsEmer returns the layer as an *emer.LayerBase,
	// to access base functionality.
	AsEmer() *LayerBase

	// Label satisfies the core.Labeler interface for getting
	// the name of objects generically. Use to access Name via interface.
	Label() string

	// TypeName is the type or category of layer, defined
	// by the algorithm (and usually set by an enum).
	TypeName() string

	// TypeNumber is the numerical value for the type or category
	// of layer, defined by the algorithm (and usually set by an enum).
	TypeNumber() int

	// UnitVarIndex returns the index of given variable within
	// the Neuron, according to *this layer's* UnitVarNames() list
	// (using a map to lookup index), or -1 and error message if
	// not found.
	UnitVarIndex(varNm string) (int, error)

	// UnitValue1D returns value of given variable index on given unit,
	// using 1-dimensional index, and a data parallel index di,
	// for networks capable of processing multiple input patterns
	// in parallel. Returns NaN on invalid index.
	// This is the core unit var access method used by other methods,
	// so it is the only one that needs to be updated for derived layer types.
	UnitValue1D(varIndex int, idx, di int) float32

	// VarRange returns the min / max values for given variable
	VarRange(varNm string) (min, max float32, err error)

	// NumRecvPaths returns the number of receiving pathways.
	NumRecvPaths() int

	// RecvPath returns a specific receiving pathway.
	RecvPath(idx int) Path

	// NumSendPaths returns the number of sending pathways.
	NumSendPaths() int

	// SendPath returns a specific sending pathway.
	SendPath(idx int) Path

	// RecvPathValues fills in values of given synapse variable name,
	// for pathway from given sending layer and neuron 1D index,
	// for all receiving neurons in this layer,
	// into given float32 slice (only resized if not big enough).
	// pathType is the string representation of the path type;
	// used if non-empty, useful when there are multiple pathways
	// between two layers.
	// Returns error on invalid var name.
	// If the receiving neuron is not connected to the given sending
	// layer or neuron then the value is set to math32.NaN().
	// Returns error on invalid var name or lack of recv path
	// (vals always set to nan on path err).
	RecvPathValues(vals *[]float32, varNm string, sendLay Layer, sendIndex1D int, pathType string) error

	// SendPathValues fills in values of given synapse variable name,
	// for pathway into given receiving layer and neuron 1D index,
	// for all sending neurons in this layer,
	// into given float32 slice (only resized if not big enough).
	// pathType is the string representation of the path type -- used if non-empty,
	// useful when there are multiple pathways between two layers.
	// Returns error on invalid var name.
	// If the sending neuron is not connected to the given receiving layer or neuron
	// then the value is set to math32.NaN().
	// Returns error on invalid var name or lack of recv path (vals always set to nan on path err).
	SendPathValues(vals *[]float32, varNm string, recvLay Layer, recvIndex1D int, pathType string) error

	// ParamsString returns a listing of all parameters in the Layer and
	// pathways within the layer. If nonDefault is true, only report those
	// not at their default values.
	ParamsString(nonDefault bool) string

	// WriteWeightsJSON writes the weights from this layer from the
	// receiver-side perspective in a JSON text format.
	WriteWeightsJSON(w io.Writer, depth int)

	// SetWeights sets the weights for this layer from weights.Layer
	// decoded values
	SetWeights(lw *weights.Layer) error
}

Layer defines the minimal interface for neural network layers, necessary to support the visualization (NetView), I/O, and parameter setting functionality provided by emergent. Most of the standard expected functionality is defined in the LayerBase struct, and this interface only has methods that must be implemented specifically for a given algorithmic implementation.

type LayerBase

type LayerBase struct {
	// EmerLayer provides access to the emer.Layer interface
	// methods for functions defined in the LayerBase type.
	// Must set this with a pointer to the actual instance
	// when created, using InitLayer function.
	EmerLayer Layer `display:"-"`

	// Name of the layer, which must be unique within the network.
	// Layers are typically accessed directly by name, via a map.
	Name string

	// Class is for applying parameter styles across multiple layers
	// that all get the same parameters.  This can be space separated
	// with multple classes.
	Class string

	// Doc contains documentation about the layer.
	// This is displayed in a tooltip in the network view.
	Doc string

	// Off turns off the layer, removing from all computations.
	// This provides a convenient way to dynamically test for
	// the contributions of the layer, for example.
	Off bool

	// Shape of the layer, either 2D or 4D.  Although spatial topology
	// is not relevant to all algorithms, the 2D shape is important for
	// efficiently visualizing large numbers of units / neurons.
	// 4D layers have 2D Pools of units embedded within a larger 2D
	// organization of such pools.  This is used for max-pooling or
	// pooled inhibition at a finer-grained level, and biologically
	// corresopnds to hypercolumns in the cortex for example.
	// Order is outer-to-inner (row major), so Y then X for 2D;
	// 4D: Y-X unit pools then Y-X neurons within pools.
	Shape tensor.Shape

	// Pos specifies the relative spatial relationship to another
	// layer, which determines positioning.  Every layer except one
	// "anchor" layer should be positioned relative to another,
	// e.g., RightOf, Above, etc.  This provides robust positioning
	// in the face of layer size changes etc.
	// Layers are arranged in X-Y planes, stacked vertically along the Z axis.
	Pos relpos.Pos `table:"-" display:"inline"`

	// Index is a 0..n-1 index of the position of the layer within
	// the list of layers in the network.
	Index int `display:"-" edit:"-"`

	// SampleIndexes are the current set of "sample" unit indexes,
	// which are a smaller subset of units that represent the behavior
	// of the layer, for computationally intensive statistics and displays
	// (e.g., PCA, ActRF, NetView rasters), when the layer is large.
	// If none have been set, then all units are used.
	// See utility function CenterPoolIndexes that returns indexes of
	// units in the central pools of a 4D layer.
	SampleIndexes []int `table:"-"`

	// SampleShape is the shape to use for the subset of sample
	// unit indexes, in terms of an array of dimensions.
	// See Shape for more info.
	// Layers that set SampleIndexes should also set this,
	// otherwise a 1D array of len SampleIndexes will be used.
	// See utility function CenterPoolShape that returns shape of
	// units in the central pools of a 4D layer.
	SampleShape tensor.Shape `table:"-"`

	// optional metadata that is saved in network weights files,
	// e.g., can indicate number of epochs that were trained,
	// or any other information about this network that would be useful to save.
	MetaData map[string]string
}

LayerBase defines the basic shared data for neural network layers, used for managing the structural elements of a network, and for visualization, I/O, etc. Nothing algorithm-specific is implemented here

func (*LayerBase) AddClass

func (ly *LayerBase) AddClass(cls ...string) *LayerBase

AddClass adds a CSS-style class name(s) for this layer, ensuring that it is not a duplicate, and properly space separated. Returns Layer so it can be chained to set other properties too.

func (*LayerBase) AsEmer

func (ly *LayerBase) AsEmer() *LayerBase

func (*LayerBase) DisplaySize

func (ly *LayerBase) DisplaySize() math32.Vector2

DisplaySize returns the display size of this layer for the 3D view. see Pos field for general info. This is multiplied by the Pos.Scale factor to rescale layer sizes, and takes into account 2D and 4D layer structures.

func (*LayerBase) DocAppend

func (ly *LayerBase) DocAppend(doc string)

DocAppend inserts given doc string at end of any existing Doc, adding a space as appropriate.

func (*LayerBase) DocPrepend

func (ly *LayerBase) DocPrepend(doc string)

DocPrepend inserts given doc string at start of any existing Doc, adding a space as appropriate.

func (*LayerBase) GetSampleShape

func (ly *LayerBase) GetSampleShape() *tensor.Shape

GetSampleShape returns the shape to use for representative units.

func (*LayerBase) Index4DFrom2D

func (ly *LayerBase) Index4DFrom2D(x, y int) ([]int, bool)

Index4DFrom2D returns the 4D index from 2D coordinates within which inner dims are interleaved. Returns false if 2D coords are invalid.

func (*LayerBase) Is2D

func (ly *LayerBase) Is2D() bool

Is2D() returns true if this is a 2D layer (no Pools)

func (*LayerBase) Is4D

func (ly *LayerBase) Is4D() bool

Is4D() returns true if this is a 4D layer (has Pools as inner 2 dimensions)

func (*LayerBase) Label

func (ly *LayerBase) Label() string

func (*LayerBase) NumPools

func (ly *LayerBase) NumPools() int

NSubPools returns the number of sub-pools of neurons according to the shape parameters. 2D shapes have 0 sub pools. For a 4D shape, the pools are the first set of 2 Y,X dims and then the neurons within the pools are the 2nd set of 2 Y,X dims.

func (*LayerBase) NumUnits

func (ly *LayerBase) NumUnits() int

func (*LayerBase) PlaceAbove

func (ly *LayerBase) PlaceAbove(other Layer)

PlaceAbove positions the layer above the other layer, using default XAlign = Left, YAlign = Front alignment.

func (*LayerBase) PlaceBehind

func (ly *LayerBase) PlaceBehind(other Layer, space float32)

PlaceBehind positions the layer behind the other layer, with given spacing, using default XAlign = Left alignment.

func (*LayerBase) PlaceRightOf

func (ly *LayerBase) PlaceRightOf(other Layer, space float32)

PlaceRightOf positions the layer to the right of the other layer, with given spacing, using default YAlign = Front alignment.

func (*LayerBase) ReadWeightsJSON

func (ly *LayerBase) ReadWeightsJSON(r io.Reader) error

ReadWeightsJSON reads the weights from this layer from the receiver-side perspective in a JSON text format. This is for a set of weights that were saved *for one layer only* and is not used for the network-level ReadWeightsJSON, which reads into a separate structure -- see SetWeights method.

func (*LayerBase) RecvPathBySendName

func (ly *LayerBase) RecvPathBySendName(sender string) (Path, error)

RecvPathBySendName returns the receiving Path with given sending layer name (the first one if multiple exist).

func (*LayerBase) RecvPathBySendNameType

func (ly *LayerBase) RecvPathBySendNameType(sender, typeName string) (Path, error)

RecvPathBySendName returns the receiving Path with given sending layer name, with the given type name (the first one if multiple exist).

func (*LayerBase) SendPathByRecvName

func (ly *LayerBase) SendPathByRecvName(recv string) (Path, error)

SendPathByRecvName returns the sending Path with given recieving layer name (the first one if multiple exist).

func (*LayerBase) SendPathByRecvNameType

func (ly *LayerBase) SendPathByRecvNameType(recv, typeName string) (Path, error)

SendPathByRecvName returns the sending Path with given recieving layer name, with the given type name (the first one if multiple exist).

func (*LayerBase) SetSampleShape

func (ly *LayerBase) SetSampleShape(idxs, shape []int)

SetSampleShape sets the SampleIndexes, and SampleShape and as list of dimension sizes, for a subset sample of units to represent the entire layer. This is critical for large layers that are otherwise unwieldy to visualize and for computationally-intensive statistics.

func (*LayerBase) SetShape

func (ly *LayerBase) SetShape(shape ...int)

SetShape sets the layer shape and also uses default dim names.

func (*LayerBase) UnitValue

func (ly *LayerBase) UnitValue(varNm string, idx []int, di int) float32

UnitValue returns value of given variable name on given unit, using shape-based dimensional index. Returns NaN on invalid var name or index. di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*LayerBase) UnitValues

func (ly *LayerBase) UnitValues(vals *[]float32, varNm string, di int) error

UnitValues fills in values of given variable name on unit, for each unit in the layer, into given float32 slice (only resized if not big enough). di is a data parallel index di, for networks capable of processing input patterns in parallel. Returns error on invalid var name.

func (*LayerBase) UnitValuesSampleTensor

func (ly *LayerBase) UnitValuesSampleTensor(tsr tensor.Values, varNm string, di int) error

UnitValuesSampleTensor fills in values of given variable name on unit for a smaller subset of representative units in the layer, into given tensor. di is a data parallel index di, for networks capable of processing input patterns in parallel. This is used for computationally intensive stats or displays that work much better with a smaller number of units. The set of representative units are defined by SetSampleIndexes -- all units are used if no such subset has been defined. If tensor is not already big enough to hold the values, it is set to SampleShape to hold all the values if subset is defined, otherwise it calls UnitValuesTensor and is identical to that. Returns error on invalid var name.

func (*LayerBase) UnitValuesTensor

func (ly *LayerBase) UnitValuesTensor(tsr tensor.Values, varNm string, di int) error

UnitValuesTensor fills in values of given variable name on unit for each unit in the layer, into given tensor. di is a data parallel index di, for networks capable of processing input patterns in parallel. If tensor is not already big enough to hold the values, it is set to the same shape as the layer. Returns error on invalid var name.

func (*LayerBase) WriteWeightsJSONBase

func (ly *LayerBase) WriteWeightsJSONBase(w io.Writer, depth int, unitVars ...string)

WriteWeightsJSONBase writes the weights from this layer in a JSON text format. Any values in the layer MetaData will be written first, and unit-level variables in unitVars are saved as well. Then, all the receiving path data is saved.

type Network

type Network interface {
	// AsEmer returns the network as an *emer.NetworkBase,
	// to access base functionality.
	AsEmer() *NetworkBase

	// Label satisfies the core.Labeler interface for getting
	// the name of objects generically.
	Label() string

	// NumLayers returns the number of layers in the network.
	NumLayers() int

	// EmerLayer returns layer as emer.Layer interface at given index.
	// Does not do extra bounds checking.
	EmerLayer(idx int) Layer

	// MaxParallelData returns the maximum number of data inputs that can be
	// processed in parallel by the network.
	// The NetView supports display of up to this many data elements.
	MaxParallelData() int

	// NParallelData returns the current number of data inputs currently being
	// processed in parallel by the network.
	// Logging supports recording each of these where appropriate.
	NParallelData() int

	// Defaults sets default parameter values for everything in the Network.
	Defaults()

	// UpdateParams() updates parameter values for all Network parameters,
	// based on any other params that might have changed.
	UpdateParams()

	// KeyLayerParams returns a listing for all layers in the network,
	// of the most important layer-level params (specific to each algorithm).
	KeyLayerParams() string

	// KeyPathParams returns a listing for all Recv pathways in the network,
	// of the most important pathway-level params (specific to each algorithm).
	KeyPathParams() string

	// UnitVarNames returns a list of variable names available on
	// the units in this network.
	// This list determines what is shown in the NetView
	// (and the order of vars list).
	// Not all layers need to support all variables,
	// but must safely return math32.NaN() for unsupported ones.
	// This is typically a global list so do not modify!
	UnitVarNames() []string

	// UnitVarProps returns a map of unit variable properties,
	// with the key being the name of the variable,
	// and the value gives a space-separated list of
	// go-tag-style properties for that variable.
	// The NetView recognizes the following properties:
	//	- range:"##" = +- range around 0 for default display scaling
	//	- min:"##" max:"##" = min, max display range
	//	- auto-scale:"+" or "-" = use automatic scaling instead of fixed range or not.
	//	- zeroctr:"+" or "-" = control whether zero-centering is used
	//	- desc:"txt" tooltip description of the variable
	//	- cat:"cat" variable category, for category tabs
	UnitVarProps() map[string]string

	// VarCategories is a list of unit & synapse variable categories,
	// which organizes the variables into separate tabs in the network view.
	// Using categories results in a more compact display and makes it easier
	// to find variables.
	// Set the 'cat' property in the UnitVarProps, SynVarProps for each variable.
	// If no categories returned, the default is Unit, Wt.
	VarCategories() []VarCategory

	// SynVarNames returns the names of all the variables
	// on the synapses in this network.
	// This list determines what is shown in the NetView
	// (and the order of vars list).
	// Not all pathways need to support all variables,
	// but must safely return math32.NaN() for
	// unsupported ones.
	// This is typically a global list so do not modify!
	SynVarNames() []string

	// SynVarProps returns a map of synapse variable properties,
	// with the key being the name of the variable,
	// and the value gives a space-separated list of
	// go-tag-style properties for that variable.
	// The NetView recognizes the following properties:
	// range:"##" = +- range around 0 for default display scaling
	// min:"##" max:"##" = min, max display range
	// auto-scale:"+" or "-" = use automatic scaling instead of fixed range or not.
	// zeroctr:"+" or "-" = control whether zero-centering is used
	// Note: this is typically a global list so do not modify!
	SynVarProps() map[string]string

	// ReadWeightsJSON reads network weights from the receiver-side perspective
	// in a JSON text format. Reads entire file into a temporary weights.Weights
	// structure that is then passed to Layers etc using SetWeights method.
	// Call the NetworkBase version followed by any post-load updates.
	ReadWeightsJSON(r io.Reader) error

	// WriteWeightsJSON writes the weights from this network
	// from the receiver-side perspective in a JSON text format.
	// Call the NetworkBase version after pre-load updates.
	WriteWeightsJSON(w io.Writer) error
}

Network defines the minimal interface for a neural network, used for managing the structural elements of a network, and for visualization, I/O, etc. Most of the standard expected functionality is defined in the NetworkBase struct, and this interface only has methods that must be implemented specifically for a given algorithmic implementation.

type NetworkBase

type NetworkBase struct {
	// EmerNetwork provides access to the emer.Network interface
	// methods for functions defined in the NetworkBase type.
	// Must set this with a pointer to the actual instance
	// when created, using InitNetwork function.
	EmerNetwork Network `display:"-"`

	// overall name of network, which helps discriminate if there are multiple.
	Name string

	// filename of last weights file loaded or saved.
	WeightsFile string

	// map of name to layers, for EmerLayerByName methods
	LayerNameMap map[string]Layer `display:"-"`

	// minimum display position in network
	MinPos math32.Vector3 `display:"-"`

	// maximum display position in network
	MaxPos math32.Vector3 `display:"-"`

	// optional metadata that is saved in network weights files,
	// e.g., can indicate number of epochs that were trained,
	// or any other information about this network that would be useful to save.
	MetaData map[string]string

	// Rand is the random number generator for the network.
	// all random calls must use this.
	// Set seed here for weight initialization values.
	Rand randx.Rand `display:"-"`

	// Random seed to be set at the start of configuring
	// the network and initializing the weights.
	// Set this to get a different set of weights.
	RandSeed int64 `edit:"-"`
}

NetworkBase defines the basic data for a neural network, used for managing the structural elements of a network, and for visualization, I/O, etc.

func (*NetworkBase) AsEmer

func (nt *NetworkBase) AsEmer() *NetworkBase

func (*NetworkBase) EmerLayerByName

func (nt *NetworkBase) EmerLayerByName(name string) (Layer, error)

EmerLayerByName returns a layer by looking it up by name. returns error message if layer is not found.

func (*NetworkBase) EmerPathByName

func (nt *NetworkBase) EmerPathByName(name string) (Path, error)

EmerPathByName returns a path by looking it up by name. Paths are named SendToRecv = sending layer name "To" recv layer name. returns error message if path is not found.

func (*NetworkBase) Label

func (nt *NetworkBase) Label() string

func (*NetworkBase) LayoutLayers

func (nt *NetworkBase) LayoutLayers()

LayoutLayers computes the 3D layout of layers based on their relative position settings.

func (*NetworkBase) OpenWeightsFS

func (nt *NetworkBase) OpenWeightsFS(fsys fs.FS, filename string) error

OpenWeightsFS opens network weights (and any other state that adapts with learning) from a JSON-formatted file, in filesystem. If filename has .gz extension, then file is gzip uncompressed.

func (*NetworkBase) OpenWeightsJSON

func (nt *NetworkBase) OpenWeightsJSON(filename core.Filename) error

OpenWeightsJSON opens network weights (and any other state that adapts with learning) from a JSON-formatted file. If filename has .gz extension, then file is gzip uncompressed.

func (*NetworkBase) ParamsString

func (nt *NetworkBase) ParamsString(nonDefault bool) string

ParamsString returns a listing of all parameters in the Layer and pathways within the layer. If nonDefault is true, only report those not at their default values.

func (*NetworkBase) ReadWeightsJSON

func (nt *NetworkBase) ReadWeightsJSON(r io.Reader) error

ReadWeightsJSON reads network weights from the receiver-side perspective in a JSON text format. Reads entire file into a temporary weights.Weights structure that is then passed to Layers etc using SetWeights method.

func (*NetworkBase) ResetRandSeed

func (nt *NetworkBase) ResetRandSeed()

ResetRandSeed sets random seed to saved RandSeed, ensuring that the network-specific random seed generator has been created.

func (*NetworkBase) SaveParams

func (nt *NetworkBase) SaveParams(nonDefault bool, filename core.Filename) error

SaveParams saves list of parameters in Network to given file. If nonDefault is true, only report those not at their default values.

func (*NetworkBase) SaveWeightsJSON

func (nt *NetworkBase) SaveWeightsJSON(filename core.Filename) error

SaveWeightsJSON saves network weights (and any other state that adapts with learning) to a JSON-formatted file. If filename has .gz extension, then file is gzip compressed.

func (*NetworkBase) SetRandSeed

func (nt *NetworkBase) SetRandSeed(seed int64)

SetRandSeed sets random seed and calls ResetRandSeed

func (*NetworkBase) SetWeights

func (nt *NetworkBase) SetWeights(nw *weights.Network) error

SetWeights sets the weights for this network from weights.Network decoded values

func (*NetworkBase) UpdateLayerNameMap

func (nt *NetworkBase) UpdateLayerNameMap()

UpdateLayerNameMap updates the LayerNameMap.

func (*NetworkBase) VarRange

func (nt *NetworkBase) VarRange(varNm string) (min, max float32, err error)

VarRange returns the min / max values for given variable. error occurs when variable name is not found.

func (*NetworkBase) VerticalLayerLayout

func (nt *NetworkBase) VerticalLayerLayout()

VerticalLayerLayout arranges layers in a standard vertical (z axis stack) layout, by setting the Pos settings.

func (*NetworkBase) WriteWeightsJSON

func (nt *NetworkBase) WriteWeightsJSON(w io.Writer) error

WriteWeightsJSON writes the weights from this network from the receiver-side perspective in a JSON text format.

type Path

type Path interface {

	// AsEmer returns the path as an *emer.PathBase,
	// to access base functionality.
	AsEmer() *PathBase

	// Label satisfies the core.Labeler interface for getting
	// the name of objects generically. Use to access Name via interface.
	Label() string

	// TypeName is the type or category of path, defined
	// by the algorithm (and usually set by an enum).
	TypeName() string

	// TypeNumber is the numerical value for the type or category
	// of path, defined by the algorithm (and usually set by an enum).
	TypeNumber() int

	// SendLayer returns the sending layer for this pathway,
	// as an emer.Layer interface.  The actual Path implmenetation
	// can use a Send field with the actual Layer struct type.
	SendLayer() Layer

	// RecvLayer returns the receiving layer for this pathway,
	// as an emer.Layer interface.  The actual Path implmenetation
	// can use a Recv field with the actual Layer struct type.
	RecvLayer() Layer

	// NumSyns returns the number of synapses for this path.
	// This is the max idx for SynValue1D and the number
	// of vals set by SynValues.
	NumSyns() int

	// SynIndex returns the index of the synapse between given send, recv unit indexes
	// (1D, flat indexes). Returns -1 if synapse not found between these two neurons.
	// This requires searching within connections for receiving unit (a bit slow).
	SynIndex(sidx, ridx int) int

	// SynVarNames returns the names of all the variables on the synapse
	// This is typically a global list so do not modify!
	SynVarNames() []string

	// SynVarNum returns the number of synapse-level variables
	// for this paths.  This is needed for extending indexes in derived types.
	SynVarNum() int

	// SynVarIndex returns the index of given variable within the synapse,
	// according to *this path's* SynVarNames() list (using a map to lookup index),
	// or -1 and error message if not found.
	SynVarIndex(varNm string) (int, error)

	// SynValues sets values of given variable name for each synapse,
	// using the natural ordering of the synapses (sender based for Axon),
	// into given float32 slice (only resized if not big enough).
	// Returns error on invalid var name.
	SynValues(vals *[]float32, varNm string) error

	// SynValue1D returns value of given variable index
	// (from SynVarIndex) on given SynIndex.
	// Returns NaN on invalid index.
	// This is the core synapse var access method used by other methods,
	// so it is the only one that needs to be updated for derived types.
	SynValue1D(varIndex int, synIndex int) float32

	// ParamsString returns a listing of all parameters in the pathway.
	// If nonDefault is true, only report those not at their default values.
	ParamsString(nonDefault bool) string

	// WriteWeightsJSON writes the weights from this pathway
	// from the receiver-side perspective in a JSON text format.
	WriteWeightsJSON(w io.Writer, depth int)

	// SetWeights sets the weights for this pathway from weights.Path
	// decoded values
	SetWeights(pw *weights.Path) error
}

Path defines the minimal interface for a pathway which connects two layers, using a specific Pattern of connectivity, and with its own set of parameters. This supports visualization (NetView), I/O, and parameter setting functionality provided by emergent. Most of the standard expected functionality is defined in the PathBase struct, and this interface only has methods that must be implemented specifically for a given algorithmic implementation,

type PathBase

type PathBase struct {
	// EmerPath provides access to the emer.Path interface
	// methods for functions defined in the PathBase type.
	// Must set this with a pointer to the actual instance
	// when created, using InitPath function.
	EmerPath Path

	// Name of the path, which can be automatically set to
	// SendLayer().Name + "To" + RecvLayer().Name via
	// SetStandardName method.
	Name string

	// Class is for applying parameter styles across multiple paths
	// that all get the same parameters. This can be space separated
	// with multple classes.
	Class string

	// Doc contains documentation about the pathway.
	// This is displayed in a tooltip in the network view.
	Doc string

	// can record notes about this pathway here.
	Notes string

	// Pattern specifies the pattern of connectivity
	// for interconnecting the sending and receiving layers.
	Pattern paths.Pattern

	// Off inactivates this pathway, allowing for easy experimentation.
	Off bool
}

PathBase defines the basic shared data for a pathway which connects two layers, using a specific Pattern of connectivity, and with its own set of parameters. The same struct token is added to the Recv and Send layer path lists,

func (*PathBase) AddClass

func (pt *PathBase) AddClass(cls ...string) *PathBase

AddClass adds a CSS-style class name(s) for this path, ensuring that it is not a duplicate, and properly space separated. Returns Path so it can be chained to set other properties too.

func (*PathBase) AsEmer

func (pt *PathBase) AsEmer() *PathBase

func (*PathBase) IsTypeOrClass

func (pt *PathBase) IsTypeOrClass(types string) bool

IsTypeOrClass returns true if the TypeName or parameter Class for this pathway matches the space separated list of values given, using case-insensitive, "contains" logic for each match.

func (*PathBase) Label

func (pt *PathBase) Label() string

func (*PathBase) ReadWeightsJSON

func (pt *PathBase) ReadWeightsJSON(r io.Reader) error

ReadWeightsJSON reads the weights from this pathway from the receiver-side perspective in a JSON text format. This is for a set of weights that were saved *for one path only* and is not used for the network-level ReadWeightsJSON, which reads into a separate structure -- see SetWeights method.

func (*PathBase) SynValue

func (pt *PathBase) SynValue(varNm string, sidx, ridx int) float32

SynValue returns value of given variable name on the synapse between given send, recv unit indexes (1D, flat indexes). Returns math32.NaN() for access errors.

type VarCategory

type VarCategory struct {
	// Category name.
	Cat string
	// Documentation of the category, used as a tooltip.
	Doc string
}

VarCategory represents one category of unit, synapse variables.

Jump to

Keyboard shortcuts

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