The Shocks
class is an interface for registering automatic shocks to a model parameter. A shock takes a timer function, which determines when to shock the parameter; a value function, which determines how to shock the parameter; and – of course – which parameter to shock. Shocks can be turned on and off from the control panel.
The shocks object is subscriptable: shocks[key]
returns the shock registered with name=key
. See shocks.add()
. It should not be instantiated by user code; the model’s shocks object is initialized during setup and stored in model.shocks
. The shock itself is represented with the Shock
object, stored in the dict
keys of Shocks
.
Initialization Parameters
model — Helipad, required
The model object.
Methods
Click a method name for more detailed documentation.
add( name, param, valFunc, … )
Registers a shock to a parameter value. Associated with a value function, which shocks the variable, and a timer function, which determines when and how often to execute the value function.
atperiod( n )
Generates a timer function that returns
True
at one or several specified periods.clear( )
Clears all added data from the container.
everyn( n, offset )
Generates a timer function that returns
True
periodically every so many periods.hide( name )
Hides a shock from the control panel. Useful for callback functions, i.e. toggling the visibility of a shock based on the value of another parameter. Hidden shocks can be re-shown with
Shocks.show()
.randn( n )
Generates a timer function that returns
True
with some probability each period.remove( name, fname, removeall )
Removes data stored at a certain key.
show( name )
Shows a previously hidden shock after the control panel is drawn. Useful for callback functions, i.e. toggling the visibility of a shock based on the value of some parameter.
step( )
Runs through the timer functions of the registered shocks and executes the shock function for any timer function that returns
True
.This function is called from
model.step()
. It should not be called from user code.
Object Properties
shocksExceptButtons — dict{str:Shock}
The subset of
Shocks.shocks
whereshock.timerFunc
is a function and therefore render as checkboxes in the control panel.Shock — class
A class to structure the shock data stored in
Shocks.shocks
, instantiated as theShock
object.
Static Properties
multi — bool
Whether the
dict
values should store a function, or a list of functions. This is a static property and should be changed only by subclassingfuncStore
.Initial value: False
Notes and Examples