Model#

Tools for crafting models.

class HARK.model.Aggregate(dist: Distribution)#

Bases: object

Used to designate a shock as an aggregate shock. If so designated, draws from the shock will be scalar rather than array valued.

class HARK.model.Control(args)#

Bases: object

Used to designate a variabel that is a control variable.

Parameters:

args (list of str) – The labels of the variables that are in the information set of this control.

HARK.model.discretized_shock_dstn(shocks, disc_params)#

Discretizes a collection of independent shocks and combines them into one DiscreteDistributionLabeled.

Shocks are discretized only if they have a corresponding element of disc_params defined.

Parameters:
  • shocks (dict of Distribution) – A dictionary of Distributions, representing independent exogenous shocks.

  • disc_params (dict of dict) – A dictionary of dictionaries with arguments to Distribution.discretize. Keys of this dictionary should be shared with the shocks argument.

HARK.model.construct_shocks(shock_data, scope)#

Returns a dictionary from shock labels to Distributions.

When the corresponding value in shock_data contains a distribution constructor and input information, any symbolic expressions used in the inputs are evaluated in the provided scope.

Parameters:

shock_data (Mapping(str, Distribution or tuple)) –

A mapping from variable names to Distribution objects, representing exogenous shocks.

Optionally, the mapping can be to tuples of Distribution constructors and dictionary of input arguments. In this case, the dictionary can map argument names to numbers, or to strings. The strings are parsed as mathematical expressions and evaluated in the scope of a calibration dictionary.

scope: dict(str, values)

Variables assigned to numerical values. The scope in which expressions will be evaluated

HARK.model.simulate_dynamics(dynamics: Mapping[str, Callable | Control], pre: Mapping[str, Any], dr: Mapping[str, Callable])#

From the beginning-of-period state (pre), follow the dynamics, including any decision rules, to compute the end-of-period state.

Parameters:

dynamics (Mapping[str, Callable]) – Maps variable names to functions from variables to values. Can include Controls ## TODO: Make collection of equations into a named type

preMapping[str, Any]

Bound values for all variables that must be known before beginning the period’s dynamics.

drMapping[str, Callable]

Decision rules for all the Control variables in the dynamics.

class HARK.model.Block#

Bases: object

class HARK.model.DBlock(name: str = '', description: str = '', shocks: dict = <factory>, dynamics: dict = <factory>, reward: dict = <factory>)#

Bases: Block

Represents a ‘block’ of model behavior. It prioritizes a representation of the dynamics of the block. Control variables are designated by the appropriate dynamic rule.

Parameters:
  • shocks (Mapping(str, Distribution or tuple)) –

    A mapping from variable names to Distribution objects, representing exogenous shocks.

    Optionally, the mapping can be to tuples of Distribution constructors and dictionary of input arguments. In this case, the dictionary can map argument names to numbers, or to strings. The strings are parsed as mathematical expressions and evaluated in the scope of a calibration dictionary.

  • dynamics (Mapping(str, str or callable)) – A dictionary mapping variable names to mathematical expressions. These expressions can be simple functions, in which case the argument names should match the variable inputs. Or these can be strings, which are parsed into functions.

name: str = ''#
description: str = ''#
shocks: dict#
dynamics: dict#
reward: dict#
construct_shocks(calibration)#

Constructs all shocks given calibration. This method mutates the DBlock.

discretize(disc_params)#

Returns a new DBlock which is a copy of this one, but with shock discretized.

get_shocks()#
get_dynamics()#
get_vars()#
transition(pre, dr)#

Returns variable values given previous values and decision rule for all controls.

calc_reward(vals)#

Computes the reward for a given set of variable values

get_state_rule_value_function_from_continuation(continuation)#

Given a continuation value function, returns a state-rule value function: the value for each state and decision rule. This value includes both the reward for executing the rule ‘this period’, and the continuation value of the resulting states.

get_decision_value_function(dr, continuation)#

Given a decision rule and a continuation value function, return a function for the value at the decision step/tac, after the shock have been realized.

get_arrival_value_function(disc_params, dr, continuation)#

Returns an arrival value function, which is the value of the states upon arrival into the block.

This involves taking an expectation over shocks (which must first be discretized), a decision rule, and a continuation value function.)

class HARK.model.RBlock(name: str = '', description: str = '', blocks: ~typing.List[~HARK.model.Block] = <factory>)#

Bases: Block

A recursive block.

Parameters:

...

name: str = ''#
description: str = ''#
blocks: List[Block]#
construct_shocks(calibration)#

Construct all shocks given a calibration dictionary.

discretize(disc_params)#

Recursively discretizes all the blocks. It replaces any DBlocks with new blocks with discretized shocks.

get_shocks()#
get_controls()#
get_dynamics()#
get_vars()#