params

package
v2.0.0-dev0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 24 Imported by: 20

README

Docs: GoDoc

See Wiki Params page for detailed docs.

Package params provides general-purpose parameter management functionality for organizing multiple sets of parameters efficiently, and basic IO for saving / loading from JSON files and generating Go code to embed into applications, and a basic GUI for viewing and editing.

IMPORTANT: as of July, 2023, params has been deprecated in favor of netparams which is focused only on Network params, for which the styling and structure of this params system makes the most sense. Use econfig for setting params on standard struct objects such as Config structs.

The main overall unit that is generally operated upon at run-time is the params.Set, which is a collection of params.Sheet's (akin to CSS style sheets) that constitute a coherent set of parameters. Here's the structure:

Sets {
    Set: "Base" {
        Sheets {
            "Network": {
                Sel: "Layer" {
                    Params: {
                        "Layer.Inhib.Layer.Gi": "1.1",
                        ...
                    }
                },
                Sel: ".Back" {
                    Params: {
                        "Prjn.PrjnScale.Rel": "0.2",
                        ...
                    }
                }
            },
            "Sim": {
                ...
            }
        }
    },
    Set: "Option1" {
        ...
    }
}        

A good strategy is to have a "Base" Set that has all the best parameters so far, and then other sets can modify specific params relative to that one. Order of application is critical, as subsequent params applications overwrite earlier ones, and the typical order is:

  • Defaults() method called that establishes the hard-coded default parameters.
  • Then apply "Base" params.Set for any changes relative to those.
  • Then optionally apply one or more additional params.Set's with current experimental parameters.

Critically, all of this is entirely up to the particular model program(s) to determine and control -- this package just provides the basic data structures for holding all of the parameters, and the IO / and Apply infrastructure.

Within a params.Set, multiple different params.Sheet's can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Each params.Sheet consists of a collection of params.Sel elements which actually finally contain the parameters. The Sel field specifies a CSS-style selector determining over what scope the parameters should be applied:

  • Type (no prefix) = name of a type -- anything having this type name will get these params.

  • .Class = anything with a given class label (each object can have multiple Class labels and thus receive multiple parameter settings, but again, order matters!)

  • #Name = a specific named object.

The order of application within a given Sheet is also critical -- typically put the most general Type params first, then .Class, then the most specific #Name cases, to achieve within a given Sheet the same logic of establishing Base params for all types and then more specific overrides for special cases (e.g., an overall learning rate that appplies across all projections, but maybe a faster or slower one for a .Class or specific #Name'd projection).

There is a params.Styler interface with methods that any Go type can implement to provide these different labels. The emer.Network, .Layer, and .Prjn interfaces each implement this interface.

Otherwise, the Apply method will just directly apply params to a given struct type if it does not implement the Styler interface.

Parameter values are stored as strings, which can represent any value.

Finally, there are methods to show where params.Set's set the same parameter differently, and to compare with the default settings on a given object type using go struct field tags of the form def:"val1[,val2...]".

Providing direct access to specific params

The best way to provide the user direct access to specific parameter values through the Params mechanisms is to put the relevant params in the Sim object, where they will be editable fields, and then call SetFloat or SetString as appropriate with the path to the parameter in question, followed by a call to apply the params.

The current value can be obtained by the ParamVal methods.

Documentation

Overview

Package params provides general-purpose parameter management functionality for organizing multiple sets of parameters efficiently, and basic IO for saving / loading from JSON files and generating Go code to embed into applications, and a basic GUI for viewing and editing.

The main overall unit that is generally operated upon at run-time is the params.Set, which is a collection of params.Sheet's (akin to CSS style sheets) that constitute a coherent set of parameters.

A good strategy is to have a "Base" Set that has all the best parameters so far, and then other sets can modify specific params relative to that one. Order of application is critical, as subsequent params applications overwrite earlier ones, and the typical order is:

  • Defaults() method called that establishes the hard-coded default parameters.
  • Then apply "Base" params.Set for any changes relative to those.
  • Then optionally apply one or more additional params.Set's with current experimental parameters.

Critically, all of this is entirely up to the particular model program(s) to determine and control -- this package just provides the basic data structures for holding all of the parameters, and the IO / and Apply infrastructure.

Within a params.Set, multiple different params.Sheet's can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Each params.Sheet consists of a collection of params.Sel elements which actually finally contain the parameters. The Sel field specifies a CSS-style selector determining over what scope the parameters should be applied:

* Type = name of a type -- anything having this type name will get these params.

* .Class = anything with a given class label (each object can have multiple Class labels and thus receive multiple parameter settings, but again, order matters!)

* #Name = a specific named object.

The order of application within a given Sheet is also critical -- typically put the most general Type params first, then .Class, then the most specific #Name cases, to achieve within a given Sheet the same logic of establishing Base params for all types and then more specific overrides for special cases (e.g., an overall learning rate that appplies across all projections, but maybe a faster or slower one for a .Class or specific #Name'd projection).

There is a params.Styler interface with methods that any Go type can implement to provide these different labels. The emer.Network, .Layer, and .Prjn interfaces each implement this interface.

Otherwise, the Apply method will just directly apply params to a given struct type if it does not implement the Styler interface.

Parameter values are limited to float64 values *only*. These can be specified using "enum" style const integer values, and can be applied to any numeric type (they will be automatically converted), but internally this is the only parameter value type, which greatly simplifies the overall interface, and handles the vast majority of use-cases (especially because named options are just integers and can be set as such).

Finally, there are methods to show where params.Set's set the same parameter differently, and to compare with the default settings on a given object type using go struct field tags of the form default:"val1[,val2...]".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClass

func AddClass(cur string, class ...string) string

AddClass adds given class(es) to current class string, ensuring it is not a duplicate of existing, and properly adding spaces

func ApplyMap

func ApplyMap(obj any, vals map[string]any, setMsg bool) error

ApplyMap applies given map[string]any values, where the map keys are a Path and the value is the value to apply (any appropriate type). This is not for Network params, which should use MapToSheet -- see emer.Params wrapper. If setMsg is true, then a message is printed to confirm each parameter that is set. It always prints a message if a parameter fails to be set, and returns an error.

func ClassMatch

func ClassMatch(sel, cls string) bool

ClassMatch returns true if given class names. handles space-separated multiple class names

func FindParam

func FindParam(val reflect.Value, path string) (reflect.Value, error)

FindParam parses the path and recursively tries to find the parameter pointed to by the path (dot-delimited field names). Returns error if not found, and always also emits error messages -- the target type should already have been identified and this should only be called when there is an expectation of the path working.

func GetParam

func GetParam(obj any, path string) (float64, error)

GetParam gets parameter value at given path on given object. converts target type to float64. returns error if path not found or target is not a numeric type (always logged).

func PathAfterType

func PathAfterType(path string) string

PathAfterType returns the portion of a path string after the initial type, e.g., Layer.Acts.Kir.Gbar -> Acts.Kir.Gbar

func SelMatch

func SelMatch(sel string, name, cls, styp, gotyp string) bool

SelMatch returns true if Sel selector matches the target object properties

func SetParam

func SetParam(obj any, path string, val string) error

SetParam sets parameter at given path on given object to given value converts the string param val as appropriate for target type. returns error if path not found or cannot set (always logged).

func Tweak

func Tweak(v float32, log, incr bool) []float32

Tweak returns parameters to try below and above the given value. log: use the quasi-log scheme: 1, 2, 5, 10 etc. Only if val is one of these vals. incr: use increments around current value: e.g., if .5, returns .4 and .6. These apply to the 2nd significant digit (remainder after most significant digit) if that is present in the original value.

func WriteGoPrelude

func WriteGoPrelude(w io.Writer, varNm string)

WriteGoPrelude writes the start of a go file in package main that starts a variable assignment to given variable -- for start of SaveGoCode methods.

Types

type Flex

type Flex map[string]*FlexVal

Flex supports arbitrary named parameter values that can be set by a Set of parameters, as a map of any objects. First initialize the map with set of names and a type to create blank values, then apply the Set to it.

func (*Flex) ApplySheet

func (fl *Flex) ApplySheet(sheet *Sheet, setMsg bool)

ApplySheet applies given sheet of parameters to each element in Flex

func (*Flex) Class

func (fl *Flex) Class() string

func (*Flex) CopyFrom

func (fl *Flex) CopyFrom(cp Flex)

CopyFrom copies hyper vals from source

func (*Flex) Init

func (fl *Flex) Init(vals []FlexVal)

Init initializes the Flex map with given set of flex values.

func (*Flex) JSONString

func (fl *Flex) JSONString() string

JSONString returns a string representation of Flex params

func (*Flex) Make

func (fl *Flex) Make()

Make makes the map if it is nil (otherwise does nothing)

func (*Flex) Name

func (fl *Flex) Name() string

func (*Flex) SaveJSON

func (fl *Flex) SaveJSON(filename core.Filename) error

SaveJSON saves hypers to a JSON-formatted file.

func (*Flex) TypeName

func (fl *Flex) TypeName() string

func (*Flex) WriteJSON

func (fl *Flex) WriteJSON(w io.Writer) error

WriteJSON saves hypers to a JSON-formatted file.

type FlexVal

type FlexVal struct {
	// name of this specific object, matches #Name selections
	Nm string

	// type name of this object, matches plain TypeName selections
	Type string

	// space-separated list of class name(s), match the .Class selections
	Cls string

	// actual object with data that is set by the parameters
	Obj any

	// History of params applied
	History HistoryImpl `tableview:"-"`
}

FlexVal is a specific flexible value for the Flex parameter map that implements the StylerObj interface for CSS-style selection logic. The field names are abbreviated because full names are used in StylerObj.

func (*FlexVal) Class

func (fv *FlexVal) Class() string

func (*FlexVal) CopyFrom

func (fv *FlexVal) CopyFrom(cp *FlexVal)

func (*FlexVal) Name

func (fv *FlexVal) Name() string

func (*FlexVal) Object

func (fv *FlexVal) Object() any

func (*FlexVal) ParamsApplied

func (fv *FlexVal) ParamsApplied(sel *Sel)

ParamsApplied is just to satisfy History interface so reset can be applied

func (*FlexVal) ParamsHistoryReset

func (fv *FlexVal) ParamsHistoryReset()

ParamsHistoryReset resets parameter application history

func (*FlexVal) TypeName

func (fv *FlexVal) TypeName() string

type History

type History interface {
	// ParamsHistoryReset resets parameter application history
	ParamsHistoryReset()

	// ParamsApplied is called when a parameter is successfully applied for given selector
	ParamsApplied(sel *Sel)
}

The params.History interface records history of parameters applied to a given object.

type HistoryImpl

type HistoryImpl []*Sel

HistoryImpl implements the History interface. Implementing object can just pass calls to a HistoryImpl field.

func (*HistoryImpl) ParamsApplied

func (hi *HistoryImpl) ParamsApplied(sel *Sel)

ParamsApplied is called when a parameter is successfully applied for given selector

func (*HistoryImpl) ParamsHistory

func (hi *HistoryImpl) ParamsHistory() Params

ParamsHistory returns the sequence of params applied for each parameter from all Sel's applied, in reverse order

func (*HistoryImpl) ParamsHistoryReset

func (hi *HistoryImpl) ParamsHistoryReset()

ParamsHistoryReset resets parameter application history

type HyperValues

type HyperValues map[string]string //types:add

HyperValues is a string-value map for storing hyperparameter values

func (*HyperValues) CopyFrom

func (hv *HyperValues) CopyFrom(cp HyperValues)

CopyFrom copies from another HyperValues

func (*HyperValues) JSONString

func (hv *HyperValues) JSONString() string

JSONString returns hyper values as a JSON formatted string

func (*HyperValues) SetJSONString

func (hv *HyperValues) SetJSONString(str string) error

SetJSONString sets from a JSON_formatted string

type Hypers

type Hypers map[string]HyperValues //types:add

Hypers is a parallel structure to Params which stores information relevant to hyperparameter search as well as the values. Use the key "Val" for the default value. This is equivalant to the value in Params. "Min" and "Max" guid the range, and "Sigma" describes a Gaussian.

func (*Hypers) Apply

func (pr *Hypers) Apply(obj any, setMsg bool) error

Apply applies all parameter values to given object. Object must already be the appropriate target type based on the first element of the path (see TargetType method). If setMsg is true, then it will log a confirmation that the parameter was set (it always prints an error message if it fails to set the parameter at given path, and returns error if so).

func (*Hypers) CopyFrom

func (pr *Hypers) CopyFrom(cp Hypers)

CopyFrom copies hyper vals from source

func (*Hypers) DeleteValOnly

func (pr *Hypers) DeleteValOnly()

DeleteValOnly deletes entries that only have a "Val" entry. This happens when applying a param Sheet using Flex params to compile values using styling logic

func (*Hypers) OpenJSON

func (pr *Hypers) OpenJSON(filename core.Filename) error

OpenJSON opens hypers from a JSON-formatted file.

func (*Hypers) OpenTOML

func (pr *Hypers) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Hypers) ParamByName

func (pr *Hypers) ParamByName(name string) map[string]string

ParamByName returns given parameter by name (just does the map access) Returns "" if not found -- use Try version for error

func (*Hypers) ParamByNameTry

func (pr *Hypers) ParamByNameTry(name string) (map[string]string, error)

ParamByNameTry returns given parameter, by name. Returns error if not found.

func (*Hypers) Path

func (pr *Hypers) Path(path string) string

Path returns the second part of the path after the target type, indicating the path to the specific parameter being set.

func (*Hypers) SaveGoCode

func (pr *Hypers) SaveGoCode(filename core.Filename) error

SaveGoCode saves hypers to corresponding Go initializer code.

func (*Hypers) SaveJSON

func (pr *Hypers) SaveJSON(filename core.Filename) error

SaveJSON saves hypers to a JSON-formatted file.

func (*Hypers) SaveTOML

func (pr *Hypers) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Hypers) SetByName

func (pr *Hypers) SetByName(name string, value map[string]string)

SetByName sets given parameter by name to given value. (just a wrapper around map set function)

func (*Hypers) StringGoCode

func (pr *Hypers) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Hypers) TargetType

func (pr *Hypers) TargetType() string

TargetType returns the first part of the path, indicating what type of object the params apply to. Uses the first item in the map (which is random) everything in the map must have the same target.

func (*Hypers) WriteGoCode

func (pr *Hypers) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes hypers to corresponding Go initializer code.

type Params

type Params map[string]string //types:add

Params is a name-value map for parameter values that can be applied to any numeric type in any object. The name must be a dot-separated path to a specific parameter, e.g., Prjn.Learn.Lrate The first part of the path is the overall target object type, e.g., "Prjn" or "Layer", which is used for determining if the parameter applies to a given object type.

All of the params in one map must apply to the same target type because only the first item in the map (which could be any due to order randomization) is used for checking the type of the target. Also, they all fall within the same Sel selector scope which is used to determine what specific objects to apply the parameters to.

func (*Params) Apply

func (pr *Params) Apply(obj any, setMsg bool) error

Apply applies all parameter values to given object. Object must already be the appropriate target type based on the first element of the path (see TargetType method). If setMsg is true, then it will log a confirmation that the parameter was set (it always prints an error message if it fails to set the parameter at given path, and returns error if so).

func (*Params) Diffs

func (pr *Params) Diffs(op *Params, nm1, nm2 string) string

Diffs returns comparison between all params in this params versus the other params, where the path is the same but the parameter value is different. Nm1 is the name / id of the 'this' Params, and nm2 is for the other params.

func (*Params) OpenJSON

func (pr *Params) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Params) OpenTOML

func (pr *Params) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Params) ParamByName

func (pr *Params) ParamByName(name string) string

ParamByName returns given parameter by name (just does the map access) Returns "" if not found -- use Try version for error

func (*Params) ParamByNameTry

func (pr *Params) ParamByNameTry(name string) (string, error)

ParamByNameTry returns given parameter, by name. Returns error if not found.

func (*Params) Path

func (pr *Params) Path(path string) string

Path returns the second part of the path after the target type, indicating the path to the specific parameter being set.

func (*Params) SaveGoCode

func (pr *Params) SaveGoCode(filename core.Filename) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Params) SaveJSON

func (pr *Params) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Params) SaveTOML

func (pr *Params) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Params) SetByName

func (pr *Params) SetByName(name, value string)

SetByName sets given parameter by name to given value. (just a wrapper around map set function)

func (*Params) StringGoCode

func (pr *Params) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Params) TargetType

func (pr *Params) TargetType() string

TargetType returns the first part of the path, indicating what type of object the params apply to. Uses the first item in the map (which is random) everything in the map must have the same target.

func (*Params) WriteGoCode

func (pr *Params) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type SearchValues

type SearchValues struct {
	// name of object with the parameter
	Name string

	// type of object with the parameter. This is a Base type name (e.g., Layer, Prjn),
	// that is at the start of the path in Network params.
	Type string

	// path to the parameter within the object
	Path string

	// starting value, e.g., for restoring after searching
	// before moving on to another parameter, for grid search.
	Start float32

	// values of the parameter to search
	Values []float32
}

SearchValues is a list of parameter values to search for one parameter on a given object (specified by Name), for float-valued params.

type Sel

type Sel struct {

	// selector for what to apply the parameters to, using standard css selector syntax: .Example applies to anything with a Class tag of 'Example', #Example applies to anything with a Name of 'Example', and Example with no prefix applies to anything of type 'Example'
	Sel string `width:"30"`

	// description of these parameter values -- what effect do they have?  what range was explored?  it is valuable to record this information as you explore the params.
	Desc string `width:"60"`

	// parameter values to apply to whatever matches the selector
	Params Params `view:"no-inline"`

	// Put your hyperparams here
	Hypers Hypers

	// number of times this selector matched a target during the last Apply process -- a warning is issued for any that remain at 0 -- see Sheet SelMatchReset and SelNoMatchWarn methods
	NMatch int `tableview:"-" toml:"-" json:"-" xml:"-" edit:"-"`

	// name of current Set being applied
	SetName string `tableview:"-" toml:"-" json:"-" xml:"-" edit:"-"`
}

params.Sel specifies a selector for the scope of application of a set of parameters, using standard css selector syntax (. prefix = class, # prefix = name, and no prefix = type)

func (*Sel) Apply

func (ps *Sel) Apply(obj any, setMsg bool) (bool, error)

Apply checks if Sel selector applies to this object according to (.Class, #Name, Type) using the params.Styler interface, and returns false if it does not. The TargetType of the Params is always tested against the obj's type name first. If it does apply, or is not a Styler, then the Params values are set. If setMsg is true, then a message is printed to confirm each parameter that is set. It always prints a message if a parameter fails to be set, and returns an error.

func (*Sel) OpenJSON

func (pr *Sel) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Sel) OpenTOML

func (pr *Sel) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Sel) ParamValue

func (sl *Sel) ParamValue(param string) (string, error)

ParamVal returns the value of given parameter

func (*Sel) SaveGoCode

func (pr *Sel) SaveGoCode(filename core.Filename) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sel) SaveJSON

func (pr *Sel) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Sel) SaveTOML

func (pr *Sel) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Sel) SelMatch

func (ps *Sel) SelMatch(obj any) bool

SelMatch returns true if Sel selector matches the target object properties

func (*Sel) SetFloat

func (sl *Sel) SetFloat(param string, val float64)

SetFloat sets the value of given parameter

func (*Sel) SetString

func (sl *Sel) SetString(param string, val string)

SetString sets the value of given parameter

func (*Sel) StringGoCode

func (pr *Sel) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sel) TargetTypeMatch

func (ps *Sel) TargetTypeMatch(obj any) bool

TargetTypeMatch return true if target type applies to object

func (*Sel) WriteGoCode

func (pr *Sel) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Set

type Set struct {

	// description of this param set -- when should it be used?  how is it different from the other sets?
	Desc string `width:"60"`

	// Sheet's grouped according to their target and / or function. For example,
	// "Network" for all the network params (or "Learn" vs. "Act" for more fine-grained), and "Sim" for overall simulation control parameters, "Env" for environment parameters, etc.  It is completely up to your program to lookup these names and apply them as appropriate.
	Sheets Sheets
}

Set is a collection of Sheets that constitute a coherent set of parameters -- a particular specific configuration of parameters, which the user selects to use. The Set name is stored in the Sets map from which it is typically accessed. A good strategy is to have a "Base" set that has all the best parameters so far, and then other sets can modify relative to that one. It is up to the Sim code to apply parameter sets in whatever order is desired.

Within a params.Set, multiple different params.Sheets can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Note that there is NO deterministic ordering of the Sheets due to the use of a Go map structure, which specifically randomizes order, so simply iterating over them and applying may produce unexpected results -- it is better to lookup by name.

func (*Set) Diffs

func (ps *Set) Diffs(ops *Set, name, otherName string) string

Diffs reports all the cases where the same param path is being set to different values between this set and the other set.

func (*Set) DiffsWithin

func (ps *Set) DiffsWithin() string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets

func (*Set) OpenJSON

func (pr *Set) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Set) OpenTOML

func (pr *Set) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Set) ParamValue

func (ps *Set) ParamValue(sheet, sel, param string) (string, error)

ParamVal returns the value of given parameter, in selection sel, in sheet

func (*Set) SaveJSON

func (pr *Set) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Set) SaveTOML

func (pr *Set) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Set) SetFloat

func (ps *Set) SetFloat(sheet, sel, param string, val float64) error

SetFloat sets the value of given parameter, in selection sel, in sheet

func (*Set) SetString

func (ps *Set) SetString(sheet, sel, param string, val string) error

SetString sets the value of given parameter, in selection sel, in sheet

func (*Set) SheetByName

func (ps *Set) SheetByName(name string) *Sheet

SheetByName finds given sheet by name -- returns nil if not found. Use this when sure the sheet exists -- otherwise use Try version.

func (*Set) SheetByNameTry

func (ps *Set) SheetByNameTry(name string) (*Sheet, error)

SheetByNameTry tries to find given sheet by name, and returns error if not found (also logs the error)

func (*Set) ValidateSheets

func (ps *Set) ValidateSheets(valids []string) error

ValidateSheets ensures that the sheet names are among those listed -- returns error message for any that are not. Helps catch typos and makes sure params are applied properly. Automatically logs errors.

func (*Set) WriteGoCode

func (pr *Set) WriteGoCode(w io.Writer, depth int, name string)

WriteGoCode writes params to corresponding Go initializer code.

type Sets

type Sets map[string]*Set //types:add

Sets is a collection of Set's that can be chosen among depending on different desired configurations etc. Thus, each Set represents a collection of different possible specific configurations, and different such configurations can be chosen by name to apply as desired.

func (*Sets) DiffsAll

func (ps *Sets) DiffsAll() string

DiffsAll reports all the cases where the same param path is being set to different values across different sets

func (*Sets) DiffsFirst

func (ps *Sets) DiffsFirst() string

DiffsFirst reports all the cases where the same param path is being set to different values between the "Base" set and all other sets. Only works if there is a set named "Base".

func (*Sets) DiffsWithin

func (ps *Sets) DiffsWithin(setName string) string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets in given set

func (*Sets) OpenJSON

func (pr *Sets) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Sets) OpenTOML

func (pr *Sets) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Sets) ParamValue

func (ps *Sets) ParamValue(set, sheet, sel, param string) (string, error)

ParamVal returns the value of given parameter, in selection sel, in sheet and set. Returns error if anything is not found.

func (*Sets) SaveGoCode

func (pr *Sets) SaveGoCode(filename core.Filename) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sets) SaveJSON

func (pr *Sets) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Sets) SaveTOML

func (pr *Sets) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Sets) SetByName

func (ps *Sets) SetByName(name string) *Set

SetByName returns given set by name -- for use when confident that it exists, as a nil will return if not found with no error

func (*Sets) SetByNameTry

func (ps *Sets) SetByNameTry(name string) (*Set, error)

SetByNameTry tries to find given set by name, and returns error if not found (also logs the error)

func (*Sets) SetFloat

func (ps *Sets) SetFloat(set, sheet, sel, param string, val float64) error

SetFloat sets the value of given parameter, in selection sel, in sheet and set.

func (*Sets) SetString

func (ps *Sets) SetString(set, sheet, sel, param string, val string) error

SetString sets the value of given parameter, in selection sel, in sheet and set. Returns error if anything is not found.

func (*Sets) StringGoCode

func (pr *Sets) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sets) ValidateSheets

func (ps *Sets) ValidateSheets(valids []string) error

ValidateSheets ensures that the sheet names are among those listed -- returns error message for any that are not. Helps catch typos and makes sure params are applied properly. Automatically logs errors.

func (*Sets) WriteGoCode

func (pr *Sets) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sheet

type Sheet []*Sel //types:add

Sheet is a CSS-like style-sheet of params.Sel values, each of which represents a different set of specific parameter values applied according to the Sel selector: .Class #Name or Type.

The order of elements in the Sheet list is critical, as they are applied in the order given by the list (slice), and thus later Sel's can override those applied earlier. Thus, you generally want to have more general Type-level parameters listed first, and then subsequently more specific ones (.Class and #Name)

This is the highest level of params that has an Apply method -- above this level application must be done under explicit program control.

func MapToSheet

func MapToSheet(vals map[string]any) (*Sheet, error)

MapToSheet returns a Sheet from given map[string]any values, so the Sheet can be applied as such -- e.g., for the network ApplyParams method. The map keys are Selector:Path and the value is the value to apply.

func NewSheet

func NewSheet() *Sheet

NewSheet returns a new Sheet

func (*Sheet) Apply

func (ps *Sheet) Apply(obj any, setMsg bool) (bool, error)

Apply applies entire sheet to given object, using param.Sel's in order see param.Sel.Apply() for details. returns true if any Sel's applied, and error if any errors. If setMsg is true, then a message is printed to confirm each parameter that is set. It always prints a message if a parameter fails to be set, and returns an error.

func (*Sheet) Diffs

func (ps *Sheet) Diffs(ops *Sheet, setNm1, setNm2 string) string

Diffs reports all the cases where the same param path is being set to different values between this sheeet and the other sheeet.

func (*Sheet) DiffsWithin

func (ps *Sheet) DiffsWithin(shtNm string) string

DiffsWithin reports all the cases where the same param path is being set to different values within different Sel's in this Sheet.

func (*Sheet) ElemLabel

func (sh *Sheet) ElemLabel(idx int) string

ElemLabel satisfies the core.SliceLabeler interface to provide labels for slice elements

func (*Sheet) OpenJSON

func (pr *Sheet) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Sheet) OpenTOML

func (pr *Sheet) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Sheet) ParamValue

func (sh *Sheet) ParamValue(sel, param string) (string, error)

ParamVal returns the value of given parameter, in selection sel

func (*Sheet) SaveGoCode

func (pr *Sheet) SaveGoCode(filename core.Filename) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sheet) SaveJSON

func (pr *Sheet) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Sheet) SaveTOML

func (pr *Sheet) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Sheet) SelByName

func (sh *Sheet) SelByName(sel string) *Sel

SelByName returns given selector within the Sheet, by Name. Returns nil if not found -- use Try version for error

func (*Sheet) SelByNameTry

func (sh *Sheet) SelByNameTry(sel string) (*Sel, error)

SelByNameTry returns given selector within the Sheet, by Name. Returns nil and error if not found.

func (*Sheet) SelMatchReset

func (ps *Sheet) SelMatchReset(setName string)

SelMatchReset resets the Sel.NMatch counter used to find cases where no Sel matched any target objects. Call at start of application process, which may be at an outer-loop of Apply calls (e.g., for a Network, Apply is called for each Layer and Prjn), so this must be called separately. See SelNoMatchWarn for warning call at end.

func (*Sheet) SelNoMatchWarn

func (ps *Sheet) SelNoMatchWarn(setName, objName string) error

SelNoMatchWarn issues warning messages for any Sel selectors that had no matches during the last Apply process -- see SelMatchReset. The setName and objName provide info about the Set and obj being applied. Returns an error message with the non-matching sets if any, else nil.

func (*Sheet) SetFloat

func (sh *Sheet) SetFloat(sel, param string, val float64) error

SetFloat sets the value of given parameter, in selection sel

func (*Sheet) SetString

func (sh *Sheet) SetString(sel, param string, val string) error

SetString sets the value of given parameter, in selection sel

func (*Sheet) StringGoCode

func (pr *Sheet) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sheet) WriteGoCode

func (pr *Sheet) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sheets

type Sheets map[string]*Sheet //types:add

Sheets is a map of named sheets -- used in the Set

func (*Sheets) DiffsWithin

func (ps *Sheets) DiffsWithin() string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets

func (*Sheets) OpenJSON

func (pr *Sheets) OpenJSON(filename core.Filename) error

OpenJSON opens params from a JSON-formatted file.

func (*Sheets) OpenTOML

func (pr *Sheets) OpenTOML(filename core.Filename) error

OpenTOML opens params from a TOML-formatted file.

func (*Sheets) SaveGoCode

func (pr *Sheets) SaveGoCode(filename core.Filename) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sheets) SaveJSON

func (pr *Sheets) SaveJSON(filename core.Filename) error

SaveJSON saves params to a JSON-formatted file.

func (*Sheets) SaveTOML

func (pr *Sheets) SaveTOML(filename core.Filename) error

SaveTOML saves params to a TOML-formatted file.

func (*Sheets) StringGoCode

func (pr *Sheets) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sheets) WriteGoCode

func (pr *Sheets) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Styler

type Styler interface {
	// TypeName returns the name of this type. CSS Sel selector with no prefix
	// operates on type name.  This type is used *in addition* to the actual
	// Go type name of the object, and is a kind of type-category (e.g., Layer
	// or Prjn in emergent network objects)
	TypeName() string

	// Class returns the space-separated list of class selectors (tags).
	// Parameters with a . prefix target class tags.
	// Do NOT include the. in the Class tags on Styler objects however
	// -- those are only in the Sel selector on the params.Sel.
	Class() string

	// Name returns the name of this object.
	// Parameters with a # prefix target object names, which are typically
	// unique.  Note, do not include the # prefix in the Styler name.
	Name() string
}

The params.Styler interface exposes TypeName, Class, and Name methods that allow the params.Sel CSS-style selection specifier to determine whether a given parameter applies. Adding Set versions of Name and Class methods is a good idea but not needed for this interface, so they are not included here.

type StylerObj

type StylerObj interface {
	Styler

	// Object returns the object that will have its field values set by
	// the params specifications.
	Object() any
}

The params.StylerObj interface extends Styler to include an arbitary function to access the underlying object type.

type Tweaks

type Tweaks struct {
	// the parameter path for this param
	Param string

	// the param selector that set the specific value upon which tweak is based
	Sel *Sel

	// the search values for all objects covered by this selector
	Search []SearchValues
}

Tweaks holds parameter tweak values associated with one parameter selector. Has all the object values affected for a given parameter within one selector, that has a tweak hyperparameter set.

func TweaksFromHypers

func TweaksFromHypers(hypers Flex) []*Tweaks

TweaksFromHypers uses given hyper parameters to generate a list of parameter values to search, based on simple Tweak values relative to the current param starting value, as specified by the .Hypers params. "Tweak" options: * log = logarithmic 1, 2, 5, 10 intervals * incr = increment by +/- ".1" (e.g., if .5, then .4, .6) * list of comma-delimited set of values in square brackets, e.g.: "[1.5, 1.2, 1.8]" The resulting search values are organized by the most specific selector that generated the final parameter value, upon which the param tweak was based.

Jump to

Keyboard shortcuts

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