estats

package
v1.4.31 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: BSD-3-Clause Imports: 15 Imported by: 25

README

Docs: GoDoc

estats.Stats provides maps for storing statistics as named scalar and tensor values. These stats are available in the elog.Context for use during logging -- see elog for example code.

To make relevant stats visible to users, call the Print function with a list of stat names -- this can be passed to the Netview Record method to show these stats at the bottom of the network view, and / or displayed in a Sims field.

There are 3 main data types supported: Float (float64), String, and Int. The Float interface to Tables uses float64 so for simple scalar values, it is simpler to just use the float64 instead of also supporting float32. However, for Tensor data, network data is often float32 so we have F32Tensor and F64Tensor for float32 and float64 respectively.

There are also various utility functions for computing various useful statistics.

Examples

A common use-case for example is to use F32Tensor to manage a tensor that is reused every time you need to access values on a given layer (this was commonly named ValsTsr in existing Sims):

    ly := ctxt.Net.LayerByName(lnm)
    tsr := ctxt.Stats.F32Tensor(lnm)
    ly.UnitValsTensor(tsr, "Act")
    // tsr now has the "Act" values from given layer -- can be logged, computed on, etc..

The above also now available as a convenience function named SetLayerTensor (also present in elog.Context).

Stats functions

  • SetLayerTensor does the above storing of unit values to a tensor.

  • ClosestPat finds the closest pattern in given column of given table of possible patterns, based on unit layer activations from SetLayerTensor

  • PCAStats computes PCA (principal components analysis) statistics on activity patterns in a table -- Helpful for measuring the overall information (variance) in the representations, to detect a common failure mode where a few patterns dominate over everything ("hogs").

  • Raster functions store raster-based tensor data with X axis = time and Y axis = unit values.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PCAStrongThr = 0.01

PCAStrongThr is the threshold for counting PCA eigenvalues as "strong" Applies to SVD as well.

Functions

func ClustPlot added in v1.3.24

func ClustPlot(plt *eplot.Plot2D, ix *etable.IdxView, colNm, lblNm string)

ClustPlot does one cluster plot on given table column name and label name

func ConfigPCAPlot added in v1.3.24

func ConfigPCAPlot(plt *eplot.Plot2D, dt *etable.Table, nm string)

func DiName added in v1.4.1

func DiName(name string, di int) string

DiName returns a string formatted with the given name appended with _di data index.

Types

type Stats

type Stats struct {
	Floats  map[string]float64
	Strings map[string]string
	Ints    map[string]int

	// float32 tensors used for grabbing values from layers
	F32Tensors map[string]*etensor.Float32 `desc:"float32 tensors used for grabbing values from layers"`

	// float64 tensors as needed for other computations
	F64Tensors map[string]*etensor.Float64 `desc:"float64 tensors as needed for other computations"`

	// int tensors as needed for other computations
	IntTensors map[string]*etensor.Int `desc:"int tensors as needed for other computations"`

	// [view: no-inline] confusion matrix
	Confusion confusion.Matrix `view:"no-inline" desc:"confusion matrix"`

	// similarity matrix for comparing pattern similarities
	SimMats map[string]*simat.SimMat `desc:"similarity matrix for comparing pattern similarities"`

	// analysis plots -- created by analysis routines
	Plots map[string]*eplot.Plot2D `desc:"analysis plots -- created by analysis routines"`

	// one PCA object can be reused for all PCA computations
	PCA pca.PCA `desc:"one PCA object can be reused for all PCA computations"`

	// one SVD object can be reused for all SVD computations
	SVD pca.SVD `desc:"one SVD object can be reused for all SVD computations"`

	// [view: no-inline] activation-based receptive fields
	ActRFs actrf.RFs `view:"no-inline" desc:"activation-based receptive fields"`

	// list of layer names configured for recording raster plots
	Rasters []string `desc:"list of layer names configured for recording raster plots"`

	// linear decoders
	LinDecoders map[string]*decoder.Linear `desc:"linear decoders"`

	// softmax decoders
	SoftMaxDecoders map[string]*decoder.SoftMax `desc:"softmax decoders"`

	// named timers available for timing how long different computations take (wall-clock time)
	Timers map[string]*timer.Time `desc:"named timers available for timing how long different computations take (wall-clock time)"`
}

Stats provides maps for storing statistics as named scalar and tensor values. These stats are available in the elog.Context for use during logging.

func (*Stats) ActRFsAvgNorm added in v1.1.56

func (st *Stats) ActRFsAvgNorm()

ActRFsAvgNorm calls Avg() then Norm() on ActRFs -- this is the standard way to visualize the RFs

func (*Stats) ClosestPat

func (st *Stats) ClosestPat(net emer.Network, layNm, unitVar string, di int, pats *etable.Table, colnm, namecol string) (int, float32, string)

ClosestStat finds the closest pattern in given column of given table of possible patterns, compared to layer activation pattern using given variable. Returns the row number, correlation value, and value of a column named namecol for that row if non-empty. Column must be etensor.Float32 di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) ConfigRasters

func (st *Stats) ConfigRasters(net emer.Network, maxCyc int, layers []string)

ConfigRasters configures spike rasters for given maximum number of cycles and layer names.

func (*Stats) F32Tensor

func (st *Stats) F32Tensor(name string) *etensor.Float32

F32Tensor returns a float32 tensor of given name, creating if not yet made

func (*Stats) F32TensorDi added in v1.4.1

func (st *Stats) F32TensorDi(name string, di int) *etensor.Float32

F32TensorDi returns a float32 tensor of given name, creating if not yet made Data parallel index version appends _di to name

func (*Stats) F64Tensor

func (st *Stats) F64Tensor(name string) *etensor.Float64

F64Tensor returns a float64 tensor of given name, creating if not yet made

func (*Stats) F64TensorDi added in v1.4.1

func (st *Stats) F64TensorDi(name string, di int) *etensor.Float64

F64TensorDi returns a float64 tensor of given name, creating if not yet made Data parallel index version appends _di to name

func (*Stats) Float

func (st *Stats) Float(name string) float64

Float returns Floats stat value -- prints error message and returns 0 if not found

func (*Stats) Float32 added in v1.3.27

func (st *Stats) Float32(name string) float32

Float32 returns Floats stat value converted to float32. prints error message and returns 0 if not found

func (*Stats) Float32Di added in v1.4.1

func (st *Stats) Float32Di(name string, di int) float32

Float32Di returns Floats stat value converted to float32. Data parallel index version appends _di to name, doesn't print err because often not present at the start

func (*Stats) FloatDi added in v1.4.1

func (st *Stats) FloatDi(name string, di int) float64

FloatDi returns Floats stat value -- returns 0 if not found Data parallel index version appends _di to name, doesn't print err because often not present at the start

func (*Stats) Init

func (st *Stats) Init()

Init must be called before use to create all the maps

func (*Stats) InitActRFs added in v1.1.56

func (st *Stats) InitActRFs(net emer.Network, arfs []string, varnm string) error

InitActRFs initializes a set of activation-based receptive field (ActRF) statistics, which record activation-weighted averaging of other tensor states, which can be activations in other layers, or external sensory inputs, or any kind of analytic pattern that helps to decode what the network is doing. The input is a list of colon-separated "Layer:Source" strings, where 'Layer' refers to a name of a layer in the given network, and 'Source' is either the name of another layer (checked first) or the name of a tensor stored in F32Tensors (if layer name not found). If Source is not a layer, it must be populated prior to these calls.

func (*Stats) Int

func (st *Stats) Int(name string) int

Int returns Ints stat value -- prints error message and returns 0 if not found

func (*Stats) IntDi added in v1.4.1

func (st *Stats) IntDi(name string, di int) int

IntDi returns Ints stat value -- 0 if not found Data parallel index version appends _di to name, doesn't print err because often not present at the start

func (*Stats) IntTensor added in v1.2.1

func (st *Stats) IntTensor(name string) *etensor.Int

IntTensor returns a int tensor of given name, creating if not yet made

func (*Stats) IntTensorDi added in v1.4.1

func (st *Stats) IntTensorDi(name string, di int) *etensor.Int

IntTensorDi returns a int tensor of given name, creating if not yet made Data parallel index version appends _di to name

func (*Stats) LayerVarsCorrel added in v1.3.27

func (st *Stats) LayerVarsCorrel(net emer.Network, layNm, unitVarA, unitVarB string, di int) float32

LayerVarsCorrel returns the correlation between two variables on a given layer di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) LayerVarsCorrelRep added in v1.3.27

func (st *Stats) LayerVarsCorrelRep(net emer.Network, layNm, unitVarA, unitVarB string, di int) float32

LayerVarsCorrelRep returns the correlation between two variables on a given layer Rep version uses representative units. di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) LinearDecodeTrain added in v1.3.37

func (st *Stats) LinearDecodeTrain(decName, varNm string, di int, trainVal float32) (float32, error)

LinearDecodeTrain does decoding and training on the decoder of the given name, using given training value, saving the results to Float stats named with the decoder + Out and SSE. returns SSE. di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) PCAStats

func (st *Stats) PCAStats(ix *etable.IdxView, varNm string, layers []string)

PCAStats computes PCA statistics on recorded hidden activation patterns on given log table (IdxView), and given list of layer names and variable name -- columns named "layer_var". Helpful for measuring the overall information (variance) in the representations to detect a common failure mode where a few patterns dominate over everything ("hogs"). Records Float stats as: layer_PCA_NStrong: number of eigenvalues above the PCAStrongThr threshold layer_PCA_Top5: average strength of top 5 eigenvalues layer_PCA_Next5: average strength of next 5 eigenvalues layer_PCA_Rest: average strength of remaining eigenvalues (if more than 10 total eigens) Uses SVD to compute much more efficiently than official PCA.

func (*Stats) Plot added in v1.3.24

func (st *Stats) Plot(name string) *eplot.Plot2D

Plot returns an eplot.Plot2D of given name, creating if not yet made

func (*Stats) Print

func (st *Stats) Print(stats []string) string

Print returns a formatted Name: Value string of stat values, suitable for displaying at the bottom of the NetView or otherwise printing. Looks for names of stats in order of fields in Stats object (Floats, Strings, Ints)

func (*Stats) PrintVals added in v1.3.3

func (st *Stats) PrintVals(stats, fmts []string, delim string) string

PrintVals returns values of given stats with given formats, and delimiter

func (*Stats) RasterRec

func (st *Stats) RasterRec(net emer.Network, cyc int, varNm string, di int)

RasterRec records data from layers configured with ConfigRasters using variable name, for given cycle number (X axis index) di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) ResetStartTimer

func (st *Stats) ResetStartTimer(name string) *timer.Time

ResetStartTimer resets then starts given named timer

func (*Stats) ResetTimer

func (st *Stats) ResetTimer(name string) *timer.Time

ResetTimer resets given named timer

func (*Stats) SetF32Tensor added in v1.1.56

func (st *Stats) SetF32Tensor(name string, tsr *etensor.Float32)

SetF32Tensor sets a float32 tensor of given name. Just does: st.F32Tensors[name] = tsr

func (*Stats) SetF32TensorDi added in v1.4.1

func (st *Stats) SetF32TensorDi(name string, di int, tsr *etensor.Float32)

SetF32TensorDi sets a float32 tensor of given name. Just does: st.F32Tensors[DiName(name, di)] = tsr Data parallel index version appends _di to name

func (*Stats) SetF64Tensor added in v1.1.56

func (st *Stats) SetF64Tensor(name string, tsr *etensor.Float64)

SetF64Tensor sets a float64 tensor of given name. Just does: st.F64Tensors[name] = tsr

func (*Stats) SetF64TensorDi added in v1.4.1

func (st *Stats) SetF64TensorDi(name string, di int, tsr *etensor.Float64)

SetF64TensorDi sets a float64 tensor of given name. Just does: st.F64Tensors[DiName(name, di)] = tsr Data parallel index version appends _di to name

func (*Stats) SetFloat

func (st *Stats) SetFloat(name string, value float64)

SetFloat sets Floats stat value

func (*Stats) SetFloat32 added in v1.3.27

func (st *Stats) SetFloat32(name string, value float32)

SetFloat32 sets Floats stat value using a float32 value

func (*Stats) SetFloat32Di added in v1.4.1

func (st *Stats) SetFloat32Di(name string, di int, value float32)

SetFloat32Di sets Floats stat value using a float32 value Data parallel index version appends _di to name

func (*Stats) SetFloatDi added in v1.4.1

func (st *Stats) SetFloatDi(name string, di int, value float64)

SetFloatDi sets Floats stat value Data parallel index version appends _di to name

func (*Stats) SetInt

func (st *Stats) SetInt(name string, value int)

SetInt sets Ints stat value

func (*Stats) SetIntDi added in v1.4.1

func (st *Stats) SetIntDi(name string, di int, value int)

SetIntDi sets Ints stat value Data parallel index version appends _di to name

func (*Stats) SetIntTensor added in v1.2.1

func (st *Stats) SetIntTensor(name string, tsr *etensor.Int)

SetIntTensor sets a int tensor of given name. Just does: st.IntTensors[name] = tsr

func (*Stats) SetIntTensorDi added in v1.4.1

func (st *Stats) SetIntTensorDi(name string, di int, tsr *etensor.Int)

SetIntTensorDi sets a int tensor of given name. Just does: st.IntTensors[DiName(name, di)] = tsr Data parallel index version appends _di to name

func (*Stats) SetLayerRepTensor added in v1.1.55

func (st *Stats) SetLayerRepTensor(net emer.Network, layNm, unitVar string, di int) *etensor.Float32

SetLayerRepTensor sets tensor of representative Unit values on a layer for given variable to a F32Tensor with name = layNm di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) SetLayerTensor

func (st *Stats) SetLayerTensor(net emer.Network, layNm, unitVar string, di int) *etensor.Float32

SetLayerTensor sets tensor of Unit values on a layer for given variable to a F32Tensor with name = layNm di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) SetRasterCol

func (st *Stats) SetRasterCol(sr, tsr *etensor.Float32, col int)

SetRasterCol sets column of given raster from data

func (*Stats) SetString

func (st *Stats) SetString(name string, value string)

SetString sets Strings stat value

func (*Stats) SetStringDi added in v1.4.1

func (st *Stats) SetStringDi(name string, di int, value string)

SetStringDi sets Strings stat value Data parallel index version appends _di to name

func (*Stats) SimMat

func (st *Stats) SimMat(name string) *simat.SimMat

SimMat returns a SimMat similarity matrix of given name, creating if not yet made

func (*Stats) SoftMaxDecodeTrain added in v1.3.37

func (st *Stats) SoftMaxDecodeTrain(decName, varNm string, di int, trainIdx int) (float32, error)

SoftLinearDecodeTrain does decoding and training on the decoder of the given name, using given training index value, saving the results to Float stats named with the decoder + Out and Err. Returns Err which is 1 if output != trainIdx, 0 otherwise. di is a data parallel index di, for networks capable of processing input patterns in parallel.

func (*Stats) StartTimer

func (st *Stats) StartTimer(name string) *timer.Time

StartTimer starts given named timer

func (*Stats) StopTimer

func (st *Stats) StopTimer(name string) *timer.Time

StopTimer stops given timer

func (*Stats) String

func (st *Stats) String(name string) string

String returns Strings stat value -- prints error message and returns "" if not found

func (*Stats) StringDi added in v1.4.1

func (st *Stats) StringDi(name string, di int) string

StringDi returns Strings stat value -- returns "" if not found Data parallel index version appends _di to name, doesn't print err because often not present at the start

func (*Stats) Timer

func (st *Stats) Timer(name string) *timer.Time

Timer returns timer of given name, creating if not yet made

func (*Stats) UpdateActRFs added in v1.1.56

func (st *Stats) UpdateActRFs(net emer.Network, varnm string, thr float32, di int)

UpdateActRFs updates activation-based receptive fields with a new sample of data from current network state, and updated state values which must be already updated in F32Tensors. Must have called InitActRFs first -- see it for documentation. Uses RFs configured then, grabbing network values from variable varnm, and given threshold (0.01 recommended) di is a data parallel index di, for networks capable of processing input patterns in parallel.

Jump to

Keyboard shortcuts

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