ra25x

package
v2.0.0-dev0.2.87 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: BSD-3-Clause Imports: 28 Imported by: 0

README

ra25x

This is the experimental version of ra25, used for experimenting with parameters and different algorithm variants etc.

The standard ra25 should be used as a template for new projects, and does not contain this experimental stuff.. It only has minimal parameters relative to defaults.

Documentation

Overview

ra25 runs a simple random-associator four-layer axon network that uses the standard supervised learning paradigm to learn mappings between 25 random input / output patterns defined over 5x5 input / output layers (i.e., 25 units)

Index

Constants

This section is empty.

Variables

View Source
var LayerParams = axon.LayerSheets{
	"Base": {
		{Sel: "Layer", Doc: "all defaults",
			Set: func(ly *axon.LayerParams) {
				ly.Inhib.ActAvg.Nominal = 0.06
				ly.Inhib.Layer.Gi = 1.1
				ly.Inhib.Layer.SS = 30
				ly.Inhib.Layer.FS0 = 0.1
				ly.Inhib.Layer.FSTau = 6
				ly.Inhib.Layer.FB = 0.5
				ly.Inhib.Layer.SSfTau = 20
				ly.Inhib.Layer.SSiTau = 50
				ly.Inhib.ActAvg.AdaptRate = 0.1
				ly.Inhib.ActAvg.LoTol = 0.8
				ly.Inhib.ActAvg.HiTol = 0.0
				ly.Acts.Dend.SSGi = 2.0
				ly.Acts.Decay.Act = 0.2
				ly.Acts.Decay.Glong = 0.6
				ly.Acts.NMDA.Ge = 0.006
				ly.Acts.NMDA.MgC = 1.2
				ly.Acts.NMDA.Voff = 0
				ly.Acts.NMDA.Tau = 100
				ly.Acts.Mahp.Gk = 0.05
				ly.Acts.Sahp.Gk = 0.05
				ly.Acts.Sahp.Off = 0.8
				ly.Acts.Sahp.Slope = 0.02
				ly.Acts.Sahp.CaTau = 5
				ly.Acts.GabaB.Gk = 0.015
				ly.Acts.KNa.On.SetBool(false)
				ly.Acts.AK.Gk = 0.1
				ly.Acts.VGCC.Ge = 0.02
				ly.Acts.VGCC.Ca = 25
				ly.Learn.CaLearn.Norm = 80
				ly.Learn.CaLearn.SpikeVGCC.SetBool(true)
				ly.Learn.CaLearn.SpikeVgccCa = 35
				ly.Learn.CaLearn.VgccTau = 10
				ly.Learn.CaLearn.Dt.MTau = 2
				ly.Learn.CaSpike.SpikeCaM = 8
				ly.Learn.CaSpike.CaSynTau = 30
				ly.Learn.CaSpike.Dt.MTau = 5
				ly.Learn.LearnNMDA.MgC = 1.4
				ly.Learn.LearnNMDA.Voff = 0
				ly.Learn.LearnNMDA.Ge = 0.006
				ly.Learn.LearnNMDA.Tau = 100
				ly.Learn.TrgAvgAct.RescaleOn.SetBool(true)
				ly.Learn.TrgAvgAct.SubMean = 1
				ly.Learn.TrgAvgAct.SynScaleRate = 0.0002
				ly.Learn.RLRate.On.SetBool(true)
				ly.Learn.RLRate.SigmoidMin = 0.05
				ly.Learn.RLRate.Diff.SetBool(true)
				ly.Learn.RLRate.DiffThr = 0.02
				ly.Learn.RLRate.SpikeThr = 0.1
				ly.Learn.RLRate.Min = 0.001

				ly.Learn.Timing.On.SetBool(false)
				ly.Learn.Timing.Refractory.SetBool(false)
				ly.Learn.Timing.SynCaCycles = 160
				ly.Learn.Timing.Cycles = 170
				ly.Learn.Timing.TimeDiffTau = 4
			}},
		{Sel: "#Input", Doc: "critical now to specify the activity level",
			Set: func(ly *axon.LayerParams) {
				ly.Inhib.Layer.Gi = 0.9
				ly.Acts.Clamp.Ge = 1.5
				ly.Inhib.ActAvg.Nominal = 0.15
				ly.Acts.VGCC.Ca = 1
				ly.Acts.Decay.Act = 1
				ly.Acts.Decay.Glong = 1
			}},
		{Sel: ".SuperLayer", Doc: "",
			Set: func(ly *axon.LayerParams) {
				ly.Inhib.Layer.Gi = 1.1
				ly.Inhib.ActAvg.Nominal = 0.06
				ly.Inhib.ActAvg.AdaptGi.SetBool(true)
			}},
		{Sel: "#Output", Doc: "output definitely needs lower inhib -- true for smaller layers in general",
			Set: func(ly *axon.LayerParams) {
				ly.Inhib.ActAvg.Nominal = 0.24
				ly.Inhib.ActAvg.AdaptGi.SetBool(true)
				ly.Inhib.Layer.Gi = 0.65
				ly.Inhib.Layer.SS = 30
				ly.Inhib.Layer.FB = 0.5
				ly.Acts.Spikes.Tr = 1
				ly.Acts.Clamp.Ge = 0.8
				ly.Acts.VGCC.Ca = 1
				ly.Learn.RLRate.On.SetBool(true)
				ly.Learn.RLRate.SigmoidMin = 0.05
			}},
	},
}

LayerParams sets the minimal non-default params. Base is always applied, and others can be optionally selected to apply on top of that.

View Source
var PathParams = axon.PathSheets{
	"Base": {
		{Sel: "Path", Doc: "basic path params",
			Set: func(pt *axon.PathParams) {
				pt.Learn.LRate.Base = 0.06
				pt.SWts.Adapt.LRate = 0.1
				pt.SWts.Adapt.SubMean = 1
				pt.SWts.Init.SPct = 0.5
				pt.Learn.DWt.SubMean = 1
				pt.Learn.DWt.LearnThr = .1
			}},
		{Sel: ".ToTarget", Doc: "",
			Set: func(pt *axon.PathParams) {
				pt.Learn.LRate.Base = 0.03
				pt.SWts.Adapt.SigGain = 6
			}},
		{Sel: ".BackPath", Doc: "top-down back-pathways MUST have lower relative weight scale, otherwise network hallucinates",
			Set: func(pt *axon.PathParams) {
				pt.PathScale.Rel = 0.3
			}},
	},
}

PathParams sets the minimal non-default params. Base is always applied, and others can be optionally selected to apply on top of that.

Functions

This section is empty.

Types

type Config

type Config struct {
	egui.BaseConfig

	// Params has parameter related configuration options.
	Params ParamConfig `display:"add-fields"`

	// Run has sim running related configuration options.
	Run RunConfig `display:"add-fields"`

	// Log has data logging related configuration options.
	Log LogConfig `display:"add-fields"`
}

Config has the overall Sim configuration options.

func (*Config) Defaults

func (cfg *Config) Defaults()

type Levels

type Levels int32 //enums:enum

Levels are the looping levels for running and statistics.

const (
	Cycle Levels = iota
	Trial
	Epoch
	Run
	Expt
)
const LevelsN Levels = 5

LevelsN is the highest valid value for type Levels, plus one.

func LevelsValues

func LevelsValues() []Levels

LevelsValues returns all possible values for the type Levels.

func (Levels) Desc

func (i Levels) Desc() string

Desc returns the description of the Levels value.

func (Levels) Int64

func (i Levels) Int64() int64

Int64 returns the Levels value as an int64.

func (Levels) MarshalText

func (i Levels) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Levels) SetInt64

func (i *Levels) SetInt64(in int64)

SetInt64 sets the Levels value from an int64.

func (*Levels) SetString

func (i *Levels) SetString(s string) error

SetString sets the Levels value from its string representation, and returns an error if the string is invalid.

func (Levels) String

func (i Levels) String() string

String returns the string representation of this Levels value.

func (*Levels) UnmarshalText

func (i *Levels) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Levels) Values

func (i Levels) Values() []enums.Enum

Values returns all possible values for the type Levels.

type LogConfig

type LogConfig struct {

	// SaveWeights will save final weights after each run.
	SaveWeights bool

	// Train has the list of Train mode levels to save log files for.
	Train []string `default:"['Expt', 'Run', 'Epoch']" nest:"+"`

	// Test has the list of Test mode levels to save log files for.
	Test []string `nest:"+"`
}

LogConfig has config parameters related to logging data.

type Modes

type Modes int32 //enums:enum

Modes are the looping modes (Stacks) for running and statistics.

const (
	Train Modes = iota
	Test
)
const ModesN Modes = 2

ModesN is the highest valid value for type Modes, plus one.

func ModesValues

func ModesValues() []Modes

ModesValues returns all possible values for the type Modes.

func (Modes) Desc

func (i Modes) Desc() string

Desc returns the description of the Modes value.

func (Modes) Int64

func (i Modes) Int64() int64

Int64 returns the Modes value as an int64.

func (Modes) MarshalText

func (i Modes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Modes) SetInt64

func (i *Modes) SetInt64(in int64)

SetInt64 sets the Modes value from an int64.

func (*Modes) SetString

func (i *Modes) SetString(s string) error

SetString sets the Modes value from its string representation, and returns an error if the string is invalid.

func (Modes) String

func (i Modes) String() string

String returns the string representation of this Modes value.

func (*Modes) UnmarshalText

func (i *Modes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Modes) Values

func (i Modes) Values() []enums.Enum

Values returns all possible values for the type Modes.

type ParamConfig

type ParamConfig struct {

	// Hidden1Size is the size of hidden 1 layer.
	Hidden1Size vecint.Vector2i `default:"{'X':10,'Y':10}" nest:"+"`

	// Hidden2Size is the size of hidden 2 layer.
	Hidden2Size vecint.Vector2i `default:"{'X':10,'Y':10}" nest:"+"`

	// Script is an interpreted script that is run to set parameters in Layer and Path
	// sheets, by default using the "Script" set name.
	Script string `new-window:"+" width:"100"`

	// Sheet is the extra params sheet name(s) to use (space separated
	// if multiple). Must be valid name as listed in compiled-in params
	// or loaded params.
	Sheet string

	// Tag is an extra tag to add to file names and logs saved from this run.
	Tag string

	// Note is additional info to describe the run params etc,
	// like a git commit message for the run.
	Note string

	// SaveAll will save a snapshot of all current param and config settings
	// in a directory named params_<datestamp> (or _good if Good is true),
	// then quit. Useful for comparing to later changes and seeing multiple
	// views of current params.
	SaveAll bool `nest:"+"`

	// Good is for SaveAll, save to params_good for a known good params state.
	// This can be done prior to making a new release after all tests are passing.
	// Add results to git to provide a full diff record of all params over level.
	Good bool `nest:"+"`
}

ParamConfig has config parameters related to sim params.

func (*ParamConfig) FieldWidget

func (pc *ParamConfig) FieldWidget(field string) core.Value

type RunConfig

type RunConfig struct {

	// GPUDevice selects the gpu device to use.
	GPUDevice int

	// NData is the number of data-parallel items to process in parallel per trial.
	// Is significantly faster for both CPU and GPU.  Results in an effective
	// mini-batch of learning.
	NData int `default:"16" min:"1"`

	// NThreads is the number of parallel threads for CPU computation;
	// 0 = use default.
	NThreads int `default:"0"`

	// Run is the _starting_ run number, which determines the random seed.
	// Runs counts up from there. Can do all runs in parallel by launching
	// separate jobs with each starting Run, Runs = 1.
	Run int `default:"0" flag:"run"`

	// Runs is the total number of runs to do when running Train, starting from Run.
	Runs int `default:"5" min:"1"`

	// Epochs is the total number of epochs per run.
	Epochs int `default:"1000"`

	// Trials is the total number of trials per epoch.
	// Should be an even multiple of NData.
	Trials int `default:"32"`

	// ISICycles is the number of no-input inter-stimulus interval
	// cycles at the start of the trial.
	ISICycles int `default:"0"` // note: > 0 bad for long-term stability

	// MinusCycles is the number of cycles in the minus phase per trial.
	MinusCycles int `default:"150"`

	// PlusCycles is the number of cycles in the plus phase per trial.
	PlusCycles int `default:"50"`

	// NZero is how many perfect, zero-error epochs before stopping a Run.
	NZero int `default:"0"`

	// TestInterval is how often (in epochs) to run through all the test patterns,
	// in terms of training epochs. Can use 0 or -1 for no testing.
	TestInterval int `default:"5"`

	// PCAInterval is how often (in epochs) to compute PCA on hidden
	// representations to measure variance.
	PCAInterval int `default:"10"`

	// StartWeights is the name of weights file to load at start of first run.
	StartWeights string
}

RunConfig has config parameters related to running the sim.

func (*RunConfig) Cycles

func (rc *RunConfig) Cycles() int

Cycles returns the total number of cycles per trial: ISI + Minus + Plus.

type Sim

type Sim struct {

	// simulation configuration parameters -- set by .toml config file and / or args
	Config *Config `new-window:"+"`

	// Net is the network: click to view / edit parameters for layers, paths, etc.
	Net *axon.Network `new-window:"+" display:"no-inline"`

	// Params manages network parameter setting.
	Params axon.Params `display:"inline"`

	// Loops are the control loops for running the sim, in different Modes
	// across stacks of Levels.
	Loops *looper.Stacks `new-window:"+" display:"no-inline"`

	// Envs provides mode-string based storage of environments.
	Envs env.Envs `new-window:"+" display:"no-inline"`

	// TrainUpdate has Train mode netview update parameters.
	TrainUpdate axon.NetViewUpdate `display:"inline"`

	// TestUpdate has Test mode netview update parameters.
	TestUpdate axon.NetViewUpdate `display:"inline"`

	// Root is the root tensorfs directory, where all stats and other misc sim data goes.
	Root *tensorfs.Node `display:"-"`

	// Stats has the stats directory within Root.
	Stats *tensorfs.Node `display:"-"`

	// Current has the current stats values within Stats.
	Current *tensorfs.Node `display:"-"`

	// StatFuncs are statistics functions called at given mode and level,
	// to perform all stats computations. phase = Start does init at start of given level,
	// and all intialization / configuration (called during Init too).
	StatFuncs []func(mode Modes, level Levels, phase StatsPhase) `display:"-"`

	// GUI manages all the GUI elements
	GUI egui.GUI `display:"-"`

	// RandSeeds is a list of random seeds to use for each run.
	RandSeeds randx.Seeds `display:"-"`
}

Sim encapsulates the entire simulation model, and we define all the functionality as methods on this struct. This structure keeps all relevant state information organized and available without having to pass everything around as arguments to methods, and provides the core GUI interface (note the view tags for the fields which provide hints to how things should be displayed).

func (*Sim) AddStat

func (ss *Sim) AddStat(f func(mode Modes, level Levels, phase StatsPhase))

AddStat adds a stat compute function.

func (*Sim) ApplyInputs

func (ss *Sim) ApplyInputs(mode Modes)

ApplyInputs applies input patterns from given environment for given mode. Any other start-of-trial logic can also be put here.

func (*Sim) ApplyParams

func (ss *Sim) ApplyParams()

func (*Sim) Body

func (ss *Sim) Body() *core.Body

func (*Sim) ConfigEnv

func (ss *Sim) ConfigEnv()

func (*Sim) ConfigGUI

func (ss *Sim) ConfigGUI(b tree.Node)

ConfigGUI configures the Cogent Core GUI interface for this simulation.

func (*Sim) ConfigInputs

func (ss *Sim) ConfigInputs()

func (*Sim) ConfigLoops

func (ss *Sim) ConfigLoops()

ConfigLoops configures the control loops: Training, Testing

func (*Sim) ConfigNet

func (ss *Sim) ConfigNet(net *axon.Network)

func (*Sim) ConfigSim

func (ss *Sim) ConfigSim()

func (*Sim) ConfigStats

func (ss *Sim) ConfigStats()

ConfigStats handles configures functions to do all stats computation in the tensorfs system.

func (*Sim) Init

func (ss *Sim) Init()

Init restarts the run, and initializes everything, including network weights and resets the epoch log table

func (*Sim) InitRandSeed

func (ss *Sim) InitRandSeed(run int)

InitRandSeed initializes the random seed based on current training run number

func (*Sim) MakeToolbar

func (ss *Sim) MakeToolbar(p *tree.Plan)

func (*Sim) NetViewUpdater

func (ss *Sim) NetViewUpdater(mode enums.Enum) *axon.NetViewUpdate

NetViewUpdater returns the NetViewUpdate for given mode.

func (*Sim) NewRun

func (ss *Sim) NewRun()

NewRun intializes a new Run level of the model.

func (*Sim) OpenInputs

func (ss *Sim) OpenInputs()

func (*Sim) OpenTable

func (ss *Sim) OpenTable(dir *tensorfs.Node, fsys fs.FS, fnm, name, docs string) (*table.Table, error)

OpenTable opens a table.Table from embedded content, storing the data in the given tensorfs directory.

func (*Sim) RunName

func (ss *Sim) RunName() string

RunName returns the overall run name, used for naming output logs and weight files based on params extra sheets and tag, and starting run number (for distributed runs).

func (*Sim) RunNoGUI

func (ss *Sim) RunNoGUI()

func (*Sim) RunStats

func (ss *Sim) RunStats(mode Modes, level Levels, phase StatsPhase)

RunStats runs the StatFuncs for given mode, level and phase.

func (*Sim) SetConfig

func (ss *Sim) SetConfig(cfg *Config)

func (*Sim) SetRunName

func (ss *Sim) SetRunName() string

SetRunName sets the overall run name, used for naming output logs and weight files based on params extra sheets and tag, and starting run number (for distributed runs).

func (*Sim) StatCounters

func (ss *Sim) StatCounters(mode, level enums.Enum) string

StatCounters returns counters string to show at bottom of netview.

func (*Sim) StatsInit

func (ss *Sim) StatsInit()

StatsInit initializes all the stats by calling Start across all modes and levels.

func (*Sim) StatsStart

func (ss *Sim) StatsStart(lmd, ltm enums.Enum)

StatsStart is called by Looper at the start of given level, for each iteration. It needs to call RunStats Start at the next level down. e.g., each Epoch is the start of the full set of Trial Steps.

func (*Sim) StatsStep

func (ss *Sim) StatsStep(lmd, ltm enums.Enum)

StatsStep is called by Looper at each step of iteration, where it accumulates the stat results.

func (*Sim) TestAll

func (ss *Sim) TestAll()

TestAll runs through the full set of testing items

type StatsPhase

type StatsPhase int32 //enums:enum

StatsPhase is the phase of stats processing for given mode, level. Accumulated values are reset at Start, added each Step.

const (
	Start StatsPhase = iota
	Step
)
const StatsPhaseN StatsPhase = 2

StatsPhaseN is the highest valid value for type StatsPhase, plus one.

func StatsPhaseValues

func StatsPhaseValues() []StatsPhase

StatsPhaseValues returns all possible values for the type StatsPhase.

func (StatsPhase) Desc

func (i StatsPhase) Desc() string

Desc returns the description of the StatsPhase value.

func (StatsPhase) Int64

func (i StatsPhase) Int64() int64

Int64 returns the StatsPhase value as an int64.

func (StatsPhase) MarshalText

func (i StatsPhase) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*StatsPhase) SetInt64

func (i *StatsPhase) SetInt64(in int64)

SetInt64 sets the StatsPhase value from an int64.

func (*StatsPhase) SetString

func (i *StatsPhase) SetString(s string) error

SetString sets the StatsPhase value from its string representation, and returns an error if the string is invalid.

func (StatsPhase) String

func (i StatsPhase) String() string

String returns the string representation of this StatsPhase value.

func (*StatsPhase) UnmarshalText

func (i *StatsPhase) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (StatsPhase) Values

func (i StatsPhase) Values() []enums.Enum

Values returns all possible values for the type StatsPhase.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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