Frame#

class HARK.frame.BackwardFrameReference(frame)#

Bases: object

A ‘reference’ to a frame that is in the previous period.

The graphical parents of frames that are at the “beginning” of a period will be these references to frames in the previous period.

Parameters:

frame (Frame) – The frame to which this reference refers.

name()#
class HARK.frame.ForwardFrameReference(frame)#

Bases: object

A ‘reference’ to a frame that is in the next period.

The graphical children of frames that are at the “end” of a period will have these references pointing to frames that are at the begining of the next period.

Parameters:

frame (Frame) – The frame to which this reference refers.

name()#
class HARK.frame.Frame(target: tuple, scope: tuple, default=None, transition=None, objective=None, aggregate=False, control=False, reward=False, context=None)#

Bases: object

An object representing a single ‘frame’ of an optimization problem. A frame defines some variables of a model, including what other variables (if any) they depend on for their values.

Parameters:
  • target (tuple) – A tuple of variable names

  • scope (tuple) – A tuple of variable names. The variables this frame depends on for transitions.

  • default (Distribution) – Default values for these target variables for simulation initialization.

  • transition (function) – A function from scope variables to target variables.

  • objective (function) – A function for use in the solver. [??]

  • aggregate (bool, default False) – True if the frame is an aggregate state variable.

  • control (bool, default False) – True if the frame targets are control variables.

  • reward (bool, default False) – True if the frame targets are reward variables.

  • context (dict, Optional) – A dictionary of additional values used by the transition function.

Variables:
  • parents (dict) – A dictionary of frames on which these frames depend. May include backward references.

  • children (dict) – A dictionary of frames that depend on this frame. May include forward references.

add_backwards_suffix(suffix: str)#

Change the names of any scope variables that are backward references to include an additional suffix.

add_suffix(suffix: str)#

Change the names of all variables in this frame’s target and scope (except for backward references) to include an additional suffix.

This is used when copying or repreating frames.

clear_relations()#

Empties the references to parents and children.

TODO: Better handling of this aspect of frame state

e.g. setters for the relations

name()#
class HARK.frame.FrameAgentType(model, **kwds)#

Bases: AgentType

A variation of AgentType that uses Frames to organize its simulation steps.

The FrameAgentType is initalizaed with a FrameModel, which contains all the information needed to execute generic simulation methods.

Parameters:

model (FrameModel)

Variables:

decision_rules (dict) – A dictionary of decision rules used to determine the transitions of control variables.

control_transition_age_varying(target, **context)#

Generic transition method for a control frame for when the variable has an age-varying decision rule.

cycles = 0#
initialize_sim()#

Prepares this AgentType for a new simulation. Resets the internal random number generator, makes initial states for all agents (using sim_birth), clears histories of tracked variables.

Parameters:

None

Return type:

None

sim_birth(which_agents)#

Makes new agents for the simulation. Takes a boolean array as an input, indicating which agent indices are to be “born”.

Populates model variable values with value from init property

Parameters:

which_agents (np.array(Bool)) – Boolean array of size self.AgentCount indicating which agents should be “born”.

Return type:

None

sim_one_period()#

Simulates one period for this type. Calls each frame in order. These should be defined for AgentType subclasses, except getMortality (define its components simDeath and simBirth instead) and readShocks.

Parameters:

None

Return type:

None

transition_frame(frame)#

Updates the model variables in target using the transition function. The transition function will use current model variable state as arguments.

class HARK.frame.FrameModel(frames, parameters, infinite=True)#

Bases: Model

A class that represents a model, defined in terms of Frames.

Frames can be transitional/functional, or they can be control frames (subject to an agent’s policy), or a reward frame.

FrameModels can be composed with other FrameModels into new models.

Parameters:
  • frames ([Frame]) – List of frames to include in the FrameSet.

  • parameters (dict)

  • infinite (bool) – True if the model is an infinite model, such that state variables are assumed to be available as scope for the next period’s transitions.

Variables:

frames (FrameSet[Frame]) – #Keys are tuples of strings corresponding to model variables. #Values are methods. #Each frame method should update the the variables #named in the key. #Frame order is significant here.

make_terminal()#

Remove the forward references from the end of the model, making the model “finite”.

Return type:

FrameModel

prepend(model, suffix='_0')#

Combine this FrameModel with another FrameModel.

TODO: Checks to make sure the endpoints match.

Parameters:
  • model (FrameModel)

  • suffix (str) – A suffix to add to any variables in the prepended model that have a name conflict with the old model.

Return type:

FrameModel

repeat(tv_parameters)#

Returns a new FrameModel consisting of this model repeated N times.

Parameters:

tv_parameters (dict) –

A dictionary of ‘time-varying’ parameters. Keys are (original) variable names. Values are dictionaries with:

  • Keys are parameter names.

  • Values as iterable contain time-varying parameter values. All time-varying values assumes to be of same length, N.

class HARK.frame.FrameSet#

Bases: OrderedDict

A data structure for a collection of frames.

Wraps an ordered dictionary, where keys are tuples of variable names, and values are Frames.

Preserves order. Is sliceable and has index() functions like a list. Supports lookup of frame by variable name.

iloc(k)#

Returns the frame in this frame set that corresponds to the given numerical index.

Parameters:

k (int) – The numerical index of the frame in the FrameSet

k_index(key)#
v_index(value)#
var(var_name)#

Returns the frame in this frame set that includes the named variable as a target.

Parameters:

var_name (str) – The name of a variable

HARK.frame.draw_frame_model(frame_model: FrameModel, figsize=(8, 8), dot=False)#

Draws a FrameModel as an influence diagram.

Round nodes : chance variables Square nodes: control variables Rhombus nodes: reward variables Hexagon nodes: aggregate variables