Skip to content

Commit

Permalink
kinaseq all good
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 18, 2024
1 parent 0e1b93f commit 0ae59e8
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 249 deletions.
54 changes: 54 additions & 0 deletions axon/simstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package axon

import (
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -565,3 +566,56 @@ func StatLevelAll(statsDir *tensorfs.Node, srcMode, srcLevel enums.Enum, styleFu
}
}
}

// FieldValue holds the value of a field in a struct.
type FieldValue struct {
Path string
Field reflect.StructField
Value, Parent reflect.Value
}

// StructValues returns a list of [FieldValue]s for fields of given struct,
// including any sub-fields, subject to filtering from the given should function
// which returns true for anything to include and false to exclude.
// You must pass a pointer to the object, so that the values are addressable.
func StructValues(obj any, should func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool) []*FieldValue {
var vals []*FieldValue
val := reflect.ValueOf(obj).Elem()
parName := ""
WalkFields(val, should,
func(parent reflect.Value, field reflect.StructField, value reflect.Value) {
fkind := field.Type.Kind()
fname := field.Name
if val.Interface() == parent.Interface() { // top-level
if fkind == reflect.Struct {
parName = fname
return
}
} else {
fname = parName + "." + fname
}
sv := &FieldValue{Path: fname, Field: field, Value: value, Parent: parent}
vals = append(vals, sv)
})
return vals
}

func WalkFields(parent reflect.Value, should func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool, walk func(parent reflect.Value, field reflect.StructField, value reflect.Value)) {
typ := parent.Type()
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
if !field.IsExported() {
continue
}
value := parent.Field(i)
if !should(parent, field, value) {
continue
}
if field.Type.Kind() == reflect.Struct {
walk(parent, field, value)
WalkFields(value, should, walk)
} else {
walk(parent, field, value)
}
}
}
2 changes: 2 additions & 0 deletions examples/kinaseq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ For the rate-code activations in Leabra, the product of these averages is likely

# Synapse-level integration of spikes

TODO: needs updating!

For spiking, the relative timing of pre-post spiking has been an obsession since the discovery of STDP.

However, at a computational level, capturing these pre-post timing interactions clearly requires computationally expensive synapse-level integration. Thus, a major technical issue we address is how to more efficiently integrate this synapse-level signal at the theoretically most efficient level which is when either the sender or receiver spikes, with the subsequent integration computed based on time passed instead of incrementally updating.
Expand Down
105 changes: 48 additions & 57 deletions examples/kinaseq/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,67 @@

package main

// ParamConfig has config parameters related to sim params
// ParamConfig has config parameters related to sim params.
type ParamConfig struct {
// Extra Param Sheet name(s) to use (space separated if multiple) -- must be valid name as listed in compiled-in params or loaded params

// 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

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

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

// Name of the JSON file to input saved parameters from.
File string `nest:"+"`

// 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 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:"+"`

// 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 time.
// 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:"+"`
}

// RunConfig has config parameters related to running the sim
// RunConfig has config parameters related to running the sim.
type RunConfig struct {
// use the GPU for computation -- only for testing in this model -- not faster
GPU bool `default:"false"`

// number of parallel threads for CPU computation -- 0 = use default
NThreads int `default:"2"`
// Trials is the total number of epochs per run.
Trials int `default:"10"`

// Cycles is the total number of cycles to run.
Cycles int `min:"10" default:"200"`

// starting run number -- determines the random seed -- runs counts from there -- can do all runs in parallel by launching separate jobs with each run, runs = 1
Run int `default:"0"`
// PlusCycles is the total number of plus-phase cycles per trial. For Cycles=300, use 100.
PlusCycles int `default:"50"`
}

// total number of runs to do when running Train
NRuns int `default:"1" min:"1"`
// LogConfig has config parameters related to logging data.
type LogConfig struct {

// total number of epochs per run
NEpochs int `default:"1000"`
// Save saves a log file when run in nogui mode.
Save bool
}

// total number of epochs per run
NTrials int `default:"10"`
// Config has the overall Sim configuration options.
type Config struct {

// total number of cycles (1 MSec) to run
NCycles int `min:"10" default:"200"`
// Name is the short name of the sim.
Name string `display:"-" default:"KinaseEQ"`

// number of plus cycles
PlusCycles int `default:"50"`
// Title is the longer title of the sim.
Title string `display:"-" default:"Kinase learning equations"`

// when does excitatory input into neuron come on?
OnCycle int `min:"0" default:"10"`
// URL is a link to the online README or other documentation for this sim.
URL string `display:"-" default:"https://github.com/emer/axon/blob/main/examples/kinaseq/README.md"`

// when does excitatory input into neuron go off?
OffCycle int `min:"0" default:"190"`
// Doc is brief documentation of the sim.
Doc string `display:"-" default:"This simulation explores calcium-based synaptic learning rules, specifically at the synaptic level."`

// RandomHz generates random firing rates, for testing
RandomHz bool
Expand All @@ -65,23 +74,6 @@ type RunConfig struct {

// additive difference in sending firing frequency relative to recv (recv has basic minus, plus)
SendDiffHz float32
}

// LogConfig has config parameters related to logging data
type LogConfig struct {

// if true, save final weights after each run
SaveWeights bool

// if true, save cycle log to file, as .cyc.tsv typically
Cycle bool `default:"true" nest:"+"`

// if true, save network activation etc data from testing trials, for later viewing in netview
NetData bool
}

// Config is a standard Sim config -- use as a starting point.
type Config struct {

// clamp constant Ge value -- otherwise drive discrete spiking input
GeClamp bool `default:"false"`
Expand All @@ -95,25 +87,24 @@ type Config struct {
// Inhibitory conductance
Gi float32 `min:"0" step:"0.01" default:"0.1"`

// how often to update display (in cycles)
UpdateInterval int `min:"1" default:"10"`

// specify include files here, and after configuration, it contains list of include files added
Includes []string
// Includes has a list of additional config files to include.
// After configuration, it contains list of include files added.
Includes []string `display:"-"`

// open the GUI -- does not automatically run -- if false, then runs automatically and quits
// GUI means open the GUI. Otherwise it runs automatically and quits,
// saving results to log files.
GUI bool `default:"true"`

// log debugging information
// Debug reports debugging information.
Debug bool

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

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

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

Expand Down
128 changes: 128 additions & 0 deletions examples/kinaseq/enumgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ae59e8

Please sign in to comment.