Skip to content

Commit

Permalink
major update to unit, synapse variable access (should not affect user…
Browse files Browse the repository at this point in the history
… code except a couple of cases in hip projects) -- much simpler for extending types. UnitVarIdx and SynVarIdx get index for variable, UnitVal1D, SynVal1D is fast index access used by all routines.
  • Loading branch information
Randall C. O'Reilly committed Jul 12, 2020
1 parent aa4b7a4 commit fab35b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
34 changes: 15 additions & 19 deletions emer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,33 @@ type Layer interface {
// Note: this is a global list so do not modify!
UnitVarProps() map[string]string

// UnitVarIdx 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.
UnitVarIdx(varNm string) (int, error)

// UnitVal1D returns value of given variable index on given unit, using 1-dimensional index.
// 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.
UnitVal1D(varIdx int, idx int) float32

// UnitVals 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).
// Returns error on invalid var name.
UnitVals(vals *[]float32, varnm string) error
UnitVals(vals *[]float32, varNm string) error

// UnitValsTensor fills in values of given variable name on unit
// for each unit in the layer, into given tensor.
// 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.
UnitValsTensor(tsr etensor.Tensor, varnm string) error
UnitValsTensor(tsr etensor.Tensor, varNm string) error

// UnitVal returns value of given variable name on given unit,
// using shape-based dimensional index.
// returns nil on invalid var name or index -- see Try version for error message.
UnitVal(varnm string, idx []int) float32

// UnitValTry returns value of given variable name on given unit,
// using shape-based dimensional index.
// returns error message if var name not found or invalid index.
UnitValTry(varnm string, idx []int) (float32, error)

// UnitVal1D returns value of given variable name on given unit,
// using 1-dimensional index.
// returns nil on invalid var name or index -- see Try version for error message.
UnitVal1D(varnm string, idx int) float32

// UnitVal1DTry returns value of given variable name on given unit,
// using 1-dimensional index.
// returns error message if var name not found or invalid index.
UnitVal1DTry(varnm string, idx int) (float32, error)
// Returns NaN on invalid var name or index.
UnitVal(varNm string, idx []int) float32

// RecvPrjns returns the full list of receiving projections
RecvPrjns() *Prjns
Expand Down
26 changes: 17 additions & 9 deletions emer/prjn.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,20 @@ type Prjn interface {

// SynIdx 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.
// This requires searching within connections for receiving unit (a bit slow).
SynIdx(sidx, ridx int) int

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

// SynVal1D returns value of given variable index (from SynVarIdx) on given SynIdx.
// 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 layer types.
SynVal1D(varIdx int, synIdx int) float32

// SynVals sets values of given variable name for each synapse, using the natural ordering
// of the synapses (sender based for Leabra),
// into given float32 slice (only resized if not big enough).
Expand All @@ -91,17 +102,14 @@ type Prjn interface {

// SynVal returns value of given variable name on the synapse
// between given send, recv unit indexes (1D, flat indexes).
// Returns math32.NaN() for access errors (see SynValTry for error message)
// Returns math32.NaN() for access errors.
SynVal(varNm string, sidx, ridx int) float32

// SynValTry returns value of given variable name on the synapse
// between given send, recv unit indexes (1D, flat indexes)
// returns error for access errors.
SynValTry(varNm string, sidx, ridx int) (float32, error)

// SetSynVal sets value of given variable name on the synapse
// between given send, recv unit indexes (1D, flat indexes)
// returns error for access errors.
// between given send, recv unit indexes (1D, flat indexes).
// Typically only supports base synapse variables and is not extended
// for derived types.
// Returns error for access errors.
SetSynVal(varNm string, sidx, ridx int, val float32) error

// Defaults sets default parameter values for all Prjn parameters
Expand Down

0 comments on commit fab35b9

Please sign in to comment.