Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using assignParameters as parameter set method; robust support and use across library. #947

Merged
merged 10 commits into from
Feb 18, 2021
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