Documentation ¶
Overview ¶
Package envlp defines an interface for environments, which determine the nature and sequence of States that can be used as inputs to a model and it can also accept Action responses from the model that affect how the enviroment evolves in the future.
This version uses the looper control framework to manage the incrementing of counters on the Env, instead of the Env automatically incrementing counters on its own, which is the behavior of the original `env.Env` environment.
By adhering to this interface, it is then easier to mix-and-match environments with models.
Index ¶
- type Ctr
- type Ctrs
- type CurPrvF32
- type CurPrvInt
- type CurPrvString
- type Element
- type Elements
- type Env
- type Envs
- type FixedTable
- func (ft *FixedTable) Action(element string, input etensor.Tensor)
- func (ft *FixedTable) Config(tbl *etable.IdxView, mode string)
- func (ft *FixedTable) Counter(time etime.Times) *Ctr
- func (ft *FixedTable) Counters() *Ctrs
- func (ft *FixedTable) CtrsToStats(stats *estats.Stats)
- func (ft *FixedTable) Desc() string
- func (ft *FixedTable) Init()
- func (ft *FixedTable) Mode() string
- func (ft *FixedTable) Name() string
- func (ft *FixedTable) NewOrder()
- func (ft *FixedTable) PermuteOrder()
- func (ft *FixedTable) Row() int
- func (ft *FixedTable) SetTrialNames()
- func (ft *FixedTable) State(element string) etensor.Tensor
- func (ft *FixedTable) Step()
- func (ft *FixedTable) String() string
- func (ft *FixedTable) Validate() error
- type States32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ctr ¶
type Ctr struct { Cur int `desc:"current counter value"` Prv int `view:"-" desc:"previous counter value, prior to last Incr() call (init to -1)"` Max int `desc:"maximum counter value -- only used if > 0"` Scope etime.ScopeKey `view:"-" desc:"the scope of this counter"` }
Ctr is a counter that counts increments at a given time scale. It keeps track of the previous value.
func (*Ctr) ResetIfOverMax ¶
ResetIfOverMax resets the current counter value to 0, if counter is at or over Max (only if Max > 0). returns true if reset
type Ctrs ¶
type Ctrs struct { Order []etime.ScopeKey `desc:"ordered list of the counter scopes, from outer-most (highest) to inner-most (lowest)"` Ctrs map[etime.ScopeKey]*Ctr `desc:"map of the counters by scope"` }
Ctrs contains an ordered slice of scopes, and a lookup map of counters by scope, used to manage counters in the Env.
func (*Ctrs) ByScopeTry ¶
ByScopeTry returns counter by scope key -- returns nil, error if not found
func (*Ctrs) CtrsToStats ¶
CtrsToStats sets the current counter values to estats Int values by their time names only (no eval Mode).
type CurPrvF32 ¶
CurPrvF32 is basic state management for current and previous values, float32 values
type CurPrvInt ¶
CurPrvInt is basic state management for current and previous values, int values
type CurPrvString ¶
CurPrvString is basic state management for current and previous values, string values
func (*CurPrvString) Set ¶
func (cv *CurPrvString) Set(cur string)
Set sets the new current value, copying Cur to Prv
type Element ¶
type Element struct { Name string `desc:"name of this element -- must be unique"` Shape []int `` /* 160-byte string literal not displayed */ DimNames []string `desc:"names of the dimensions within the Shape -- optional but useful for ensuring correct usage"` }
Element specifies one element of State or Action in an environment
func (*Element) FromColumn ¶
FromColumn copies element data from etable Column that describes an etable.Table
type Elements ¶
type Elements []Element
Elements is a list of Element info
func (*Elements) FromSchema ¶
FromSchema copies element data from a etable Schema that describes an etable.Table
type Env ¶
type Env interface { // Name returns a name for this environment, which can be useful // for selecting from a list of options etc. Name() string // Desc returns an (optional) brief description of this environment. Desc() string // Mode returns the evaluation mode (etime.Modes) for this environment // (Train, Test, etc). This is used for the Scope of the counters. Mode() string // Validate checks if the various specific parameters for this // Env have been properly set -- if not, error message(s) will // be returned. If everything is OK, nil is returned, in which // case calls to Counters(), States(), and Actions() should all // return valid data. It is essential that a model *always* check // this as a first step, because the Env will not generally check // for errors on any subsequent calls (for greater efficiency // and simplicity). Validate() error // Init initializes the environment at start of a new Run, preserving // the current Run level counter value, if that counter is present, but // resetting all other counters to 0. // In general the Env can expect that the Sim will have established a // different random seed per run, prior to calling this method, // sufficient to enable different run-level behavior. // The current State() must be updated to reflect the first step of // the environment, consistent with the post-increment model, where // Step is called *after* the current state is used. Init() // Step advances to the next step of environment state, // rendering any new State values as needed, and incrementing the // counter associated with stepping (e.g., Trial). // This is called *after* using the current State, making it ready // for the next iteration. // The looper control system will detect when the Trial is over Max // and reset that back to 0, while updating other higher counters as needed. // The Env should expect this and prepare a next state consistent with // the Trial (stepping level) counter reset back to 0. Step() // Counters returns the full set of counters used in the Env. // A specific scope counter can be accessed as Counters().ByScope(scope) Counters() *Ctrs // Counter returns counter for given standard etime.Times value, using // the Mode set for this environment to generate a ScopeKey string. Counter(time etime.Times) *Ctr // String returns a string representation of the current step contents. // This is typically saved as a TrialName in the CtrsToStats function, // and satisfies the standard Stringer interface. String() string // State returns the given element's worth of tensor data from the environment // based on the current state of the env (prepared by Init or the last Step). // If no output is available on that element, then nil is returned. // The returned tensor must be treated as read-only as it likely points to original // source data -- please make a copy before modifying (e.g., Clone() method) State(element string) etensor.Tensor // Action sends tensor data about e.g., responses from model back to act // on the environment and influence its subsequent evolution. // The nature and timing of this input is paradigm dependent, but // in general it should happen prior to the Step() call, so that // Action sets values on the Env that are then used in the Step call // to generate the appropriate next state values. Action(element string, input etensor.Tensor) // CtrsToStats sets the current counter values to estats Int values // by their time names only (no eval Mode). These values can then // be read by elog LogItems to record the counters in logs. // Typically, a TrialName string is also expected to be set, // to describe the current trial (Step) contents in a useful way, // and other relevant info (e.g., group / category info) can also be set. CtrsToStats(stats *estats.Stats) }
Env defines an interface for environments, which determine the nature and sequence of States that can be used as inputs to a model, and the Env also can accept Action responses from the model that affect state evolution.
The Env holds a set of Ctr counters for different time scales according to the etime scoping system, which are assumed to be managed by the looper.Stack looping control system. The Env should only increment the inner-most counter that tracks the Stepping of the environment.
State is comprised of one or more elements, each of which consists of an etensor.Tensor chunk of values that can be obtained by the model. Likewise, Actions provide tensor elements as input to the Env.
type Envs ¶
Envs is a map of environments organized according to the evaluation mode string (recommended key value)
type FixedTable ¶
type FixedTable struct { Nm string `desc:"name of this environment"` Dsc string `desc:"description of this environment"` EMode string `desc:"eval mode for this env"` Table *etable.IdxView `` /* 285-byte string literal not displayed */ Sequential bool `` /* 140-byte string literal not displayed */ Order []int `desc:"permuted order of items to present if not sequential -- updated every time through the list"` Ctrs Ctrs `desc:"counters for this environment"` TrialName CurPrvString `desc:"if Table has a Name column, this is the contents of that"` GroupName CurPrvString `desc:"if Table has a Group column, this is contents of that"` NameCol string `desc:"name of the Name column -- defaults to 'Name'"` GroupCol string `desc:"name of the Group column -- defaults to 'Group'"` }
FixedTable is a basic Env that manages patterns from an etable.Table, with either sequential or permuted random ordering, and uses standard Run, Epoch, Trial etime.Times counters to record progress and iterations through the table. It uses an IdxView indexed view of the Table, so a single shared table can be used across different environments, with each having its own unique view. The State calls directly access column names in the associated table, and the Action method has no effect.
func (*FixedTable) Config ¶
func (ft *FixedTable) Config(tbl *etable.IdxView, mode string)
Config configures the environment to use given table IndexView and evaluation mode (e.g., etime.Train.String()). If mode is Train then a Run counter is added, otherwise just Epoch and Trial. NameCol and GroupCol are initialized to "Name" and "Group" so set these to something else after this if needed.
func (*FixedTable) Counters ¶
func (ft *FixedTable) Counters() *Ctrs
func (*FixedTable) CtrsToStats ¶
func (ft *FixedTable) CtrsToStats(stats *estats.Stats)
func (*FixedTable) Desc ¶
func (ft *FixedTable) Desc() string
func (*FixedTable) Init ¶
func (ft *FixedTable) Init()
func (*FixedTable) Mode ¶
func (ft *FixedTable) Mode() string
func (*FixedTable) Name ¶
func (ft *FixedTable) Name() string
func (*FixedTable) NewOrder ¶
func (ft *FixedTable) NewOrder()
NewOrder sets a new random Order based on number of rows in the table.
func (*FixedTable) PermuteOrder ¶
func (ft *FixedTable) PermuteOrder()
PermuteOrder permutes the existing order table to get a new random sequence of inputs just calls: erand.PermuteInts(ft.Order)
func (*FixedTable) Row ¶
func (ft *FixedTable) Row() int
Row returns the current row number in table, based on Sequential / perumuted Order and already de-referenced through the IdxView's indexes to get the actual row in the table.
func (*FixedTable) SetTrialNames ¶
func (ft *FixedTable) SetTrialNames()
SetTrialNames sets the TrialName and GroupName
func (*FixedTable) Step ¶
func (ft *FixedTable) Step()
func (*FixedTable) String ¶
func (ft *FixedTable) String() string
func (*FixedTable) Validate ¶
func (ft *FixedTable) Validate() error
type States32 ¶
States32 is a map of named *etensor.Float32 tensors, used by Envs to manage states.
func NewStates32 ¶
NewStates32 returns a new States32 map for given names
func (*States32) ByNameTry ¶
ByNameTry accesses the tensor map by name, generating an error if the state is not found.