From 7fa1a406e3841514cbe7fe85ffc88cff503b1a9c Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 7 Feb 2024 08:16:40 -0500 Subject: [PATCH 1/4] generate random seeds for IndexDistribution upon creation of income distribution, fixes #i1379 --- HARK/ConsumptionSaving/ConsIndShockModel.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/HARK/ConsumptionSaving/ConsIndShockModel.py b/HARK/ConsumptionSaving/ConsIndShockModel.py index 693089d5b..8cead22f6 100644 --- a/HARK/ConsumptionSaving/ConsIndShockModel.py +++ b/HARK/ConsumptionSaving/ConsIndShockModel.py @@ -3742,6 +3742,7 @@ def construct_lognormal_income_process_unemployment(self): "IncUnemp": IncUnemp_list, }, RNG=self.RNG, + seed=self.RNG.integers(0, 2**31 - 1) ) PermShkDstn = IndexDistribution( @@ -3751,6 +3752,8 @@ def construct_lognormal_income_process_unemployment(self): "n_approx": PermShkCount_list, "neutral_measure": neutral_measure_list, }, + RNG=self.RNG, + seed=self.RNG.integers(0, 2**31 - 1) ) TranShkDstn = IndexDistribution( @@ -3761,6 +3764,9 @@ def construct_lognormal_income_process_unemployment(self): "IncUnemp": IncUnemp_list, "n_approx": TranShkCount_list, }, + RNG=self.RNG, + seed=self.RNG.integers(0, 2**31 - 1) + ) return IncShkDstn, PermShkDstn, TranShkDstn From 8fac4a2f3a66ca732374715f5ca6f6d0b4f2e6de Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 7 Feb 2024 08:20:56 -0500 Subject: [PATCH 2/4] changelog update for #1379 / #1380 --- Documentation/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index d91d204f1..5c81a876f 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -29,6 +29,7 @@ Release Date: TBD - Creates a `models/` directory with Python model configurations for perfect foresight and Fisher 2-period models. [1347](https://github.com/econ-ark/HARK/pull/1347) - Fixes bug in AgentType simulations where 'who_dies' for period t was being recorded in period t-1in the history Carlo simulation functions using Python model configurations.[1296](https://github.com/econ-ark/HARK/pull/1296) - Removes unused `simulation.py` .[1296](https://github.com/econ-ark/HARK/pull/1296) +- Fixes bug that default seed was being used in the initializing of income shock distributions. [1380](https://github.com/econ-ark/HARK/pull/1380) ### 0.13.0 From 3a2b560330cc34fd686d9060fa1179aaaa076328 Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 7 Feb 2024 08:42:46 -0500 Subject: [PATCH 3/4] adding test for #1379 and fixing test that depends on simulated target value --- HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py b/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py index f1881a275..81dc92da9 100644 --- a/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py +++ b/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py @@ -115,6 +115,12 @@ def test_simulated_values(self): # simulation test -- seed/generator specific # self.assertAlmostEqual(self.agent.state_now["aLvl"][1], 0.18438, place = HARK_PRECISION) + def test_income_dist_random_seeds(self): + a1 = IndShockConsumerType(seed = 1000) + a2 = IndShockConsumerType(seed = 200) + + self.assertFalse(a1.PermShkDstn.seed == a2.PermShkDstn.seed) + class testBufferStock(unittest.TestCase): """Tests of the results of the BufferStock REMARK.""" @@ -414,7 +420,7 @@ def test_cyclical(self): CyclicalExample.simulate() self.assertAlmostEqual( - CyclicalExample.state_now["aLvl"][1], 2.41243, places=HARK_PRECISION + CyclicalExample.state_now["aLvl"][1], 3.32431, places=HARK_PRECISION ) From 834d408e66eda2f19ea47e9a29e85ad817264864 Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 7 Feb 2024 08:45:44 -0500 Subject: [PATCH 4/4] formating fixes --- HARK/ConsumptionSaving/ConsIndShockModel.py | 7 +++---- HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/HARK/ConsumptionSaving/ConsIndShockModel.py b/HARK/ConsumptionSaving/ConsIndShockModel.py index 8cead22f6..1d80b1362 100644 --- a/HARK/ConsumptionSaving/ConsIndShockModel.py +++ b/HARK/ConsumptionSaving/ConsIndShockModel.py @@ -3742,7 +3742,7 @@ def construct_lognormal_income_process_unemployment(self): "IncUnemp": IncUnemp_list, }, RNG=self.RNG, - seed=self.RNG.integers(0, 2**31 - 1) + seed=self.RNG.integers(0, 2**31 - 1), ) PermShkDstn = IndexDistribution( @@ -3753,7 +3753,7 @@ def construct_lognormal_income_process_unemployment(self): "neutral_measure": neutral_measure_list, }, RNG=self.RNG, - seed=self.RNG.integers(0, 2**31 - 1) + seed=self.RNG.integers(0, 2**31 - 1), ) TranShkDstn = IndexDistribution( @@ -3765,8 +3765,7 @@ def construct_lognormal_income_process_unemployment(self): "n_approx": TranShkCount_list, }, RNG=self.RNG, - seed=self.RNG.integers(0, 2**31 - 1) - + seed=self.RNG.integers(0, 2**31 - 1), ) return IncShkDstn, PermShkDstn, TranShkDstn diff --git a/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py b/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py index 81dc92da9..45a202259 100644 --- a/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py +++ b/HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py @@ -116,8 +116,8 @@ def test_simulated_values(self): # self.assertAlmostEqual(self.agent.state_now["aLvl"][1], 0.18438, place = HARK_PRECISION) def test_income_dist_random_seeds(self): - a1 = IndShockConsumerType(seed = 1000) - a2 = IndShockConsumerType(seed = 200) + a1 = IndShockConsumerType(seed=1000) + a2 = IndShockConsumerType(seed=200) self.assertFalse(a1.PermShkDstn.seed == a2.PermShkDstn.seed)