Skip to content

Commit

Permalink
using assignParameters as parameter set method; robust support and us…
Browse files Browse the repository at this point in the history
…e across library. (#947)

* removing model call(); adding Model init to AgentType and Market, fixes #679

* changelog for issue #934

* Removing 'Now' from model variables in ConsIndShock #920

* removing "Now" from model variable names, see #920

* changes to make ConsAggShockModel work without 'Now' in model variables, fixes #920

* changelog for #920

* removing model call(); adding Model init to AgentType and Market, fixes #679

* changelog for issue #934
  • Loading branch information
sbenthall authored Feb 18, 2021
1 parent 4ff6ea8 commit 6d79519
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions Documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interpolation for problems with CRRA utility. See [#888](https://github.com/econ
* Corrects location of constructor documentation to class string for Sphinx rendering [#908](https://github.com/econ-ark/HARK/pull/908)
* Adds a module with tools for parsing and using various income calibrations from the literature. It includes the option of using life-cycle profiles of income shock variances from [Sabelhaus and Song (2010)](https://www.sciencedirect.com/science/article/abs/pii/S0304393210000358). See [#921](https://github.com/econ-ark/HARK/pull/921), [#941](https://github.com/econ-ark/HARK/pull/941).
* remove "Now" from model variable names [#936](https://github.com/econ-ark/HARK/pull/936)
* remove Model.__call__; use Model init in Market and AgentType init to standardize on parameters dictionary [#947](https://github.com/econ-ark/HARK/issues/947)
* Moves state MrkvNow to shocks['Mrkv'] in AggShockMarkov and KrusellSmith models [#935](https://github.com/econ-ark/HARK/pull/935)
* Replaces `ConsIndShock`'s `init_lifecycle` with an actual life-cycle calibration [#951](https://github.com/econ-ark/HARK/pull/951).

Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ def test_economy(self):

self.assertAlmostEqual(self.economy.history["Aprev"][4], 11.009107526443584)

self.assertAlmostEqual(self.economy.history["Mrkv"][40], 1)
self.assertAlmostEqual(self.economy.history['Mrkv'][40], 1)

self.assertAlmostEqual(self.economy.history["Urate"][12], 0.040000000000000036)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_simulation(self):
"T_age": None, # Age after which simulated agents are automatically killed
}

self.agent_infinite(
self.agent_infinite.assignParameters(
**SimulationParams
) # This implicitly uses the assignParameters method of AgentType

Expand Down
26 changes: 21 additions & 5 deletions HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,36 @@ def assignParameters(self, **kwds):
-------
none
"""
self.parameters = kwds
self.parameters.update(kwds)
for key in kwds:
setattr(self, key, kwds[key])

def __call__(self, **kwds):
def get_parameter(self, name):
"""
Assign an arbitrary number of attributes to this agent, as a convenience.
See assignParameters.
Returns a parameter of this model
Parameters
----------
name : string
The name of the parameter to get
Returns
-------
value :
The value of the parameter
"""
self.assignParameters(**kwds)
return self.parameters[name]

def __eq__(self, other):
if isinstance(other, type(self)):
return self.parameters == other.parameters

return notImplemented

def __init__(self):
if not hasattr(self, 'parameters'):
self.parameters = {}

def __str__(self):

type_ = type(self)
Expand Down Expand Up @@ -261,6 +274,8 @@ def __init__(
seed=0,
**kwds
):
super().__init__()

if solution_terminal is None:
solution_terminal = NullFunc()

Expand Down Expand Up @@ -1116,6 +1131,7 @@ def __init__(
tolerance=0.000001,
**kwds
):
super().__init__()
self.agents = agents if agents is not None else list() # NOQA

reap_vars = reap_vars if reap_vars is not None else list() # NOQA
Expand Down

0 comments on commit 6d79519

Please sign in to comment.