From 6d7951960c45767f57de9c53e8b7b0e9bba37a15 Mon Sep 17 00:00:00 2001 From: Sebastian Benthall Date: Thu, 18 Feb 2021 11:59:05 -0500 Subject: [PATCH] using assignParameters as parameter set method; robust support and use 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 --- Documentation/CHANGELOG.md | 1 + .../tests/test_ConsAggShockModel.py | 2 +- .../tests/test_PerfForesightConsumerType.py | 2 +- HARK/core.py | 26 +++++++++++++++---- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index a29c1fa66..c05385676 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -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). diff --git a/HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py b/HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py index 3fe9f76a2..492f7babf 100644 --- a/HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py +++ b/HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py @@ -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) diff --git a/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py b/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py index a7105b1f6..9f5a7b8fe 100644 --- a/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py +++ b/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py @@ -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 diff --git a/HARK/core.py b/HARK/core.py index 3fe5a04f3..ad3bb1897 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -169,16 +169,25 @@ 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)): @@ -186,6 +195,10 @@ def __eq__(self, other): return notImplemented + def __init__(self): + if not hasattr(self, 'parameters'): + self.parameters = {} + def __str__(self): type_ = type(self) @@ -261,6 +274,8 @@ def __init__( seed=0, **kwds ): + super().__init__() + if solution_terminal is None: solution_terminal = NullFunc() @@ -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