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

The change in how distributions are handled seems to have messed simulations up #750

Merged
merged 3 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,8 @@ def constructLognormalIncomeProcessUnemployment(self):
ShkPrbsRet = np.array([1.0])
IncomeDstnRet = DiscreteDistribution(ShkPrbsRet,
[PermShkValsRet,
TranShkValsRet])
TranShkValsRet],
seed=self.RNG.randint(0, 2**31-1))

# Loop to fill in the list of IncomeDstn random variables.
for t in range(T_cycle): # Iterate over all periods, counting forward
Expand All @@ -2518,7 +2519,9 @@ def constructLognormalIncomeProcessUnemployment(self):
).approx(PermShkCount, tail_N=0)
### REPLACE
###REPLACE
IncomeDstn.append(combineIndepDstns(PermShkDstn_t,TranShkDstn_t)) # mix the independent distributions
IncomeDstn.append(combineIndepDstns(PermShkDstn_t,
TranShkDstn_t,
seed = self.RNG.randint(0, 2**31-1))) # mix the independent distributions
PermShkDstn.append(PermShkDstn_t)
TranShkDstn.append(TranShkDstn_t)
return IncomeDstn, PermShkDstn, TranShkDstn
Expand Down
4 changes: 2 additions & 2 deletions HARK/ConsumptionSaving/ConsPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def getRisky(self):

mu = np.log(RiskyAvg / (np.sqrt(1. + RiskyVar / RiskyAvgSqrd)))
sigma = np.sqrt(np.log(1. + RiskyVar / RiskyAvgSqrd))
self.RiskyNow = Lognormal(mu, sigma).draw(1, seed=self.RNG.randint(0, 2**31-1))
self.RiskyNow = Lognormal(mu, sigma, seed=self.RNG.randint(0, 2**31-1)).draw(1)


def getAdjust(self):
Expand All @@ -370,7 +370,7 @@ def getAdjust(self):
-------
None
'''
self.AdjustNow = Bernoulli(self.AdjustPrb).draw(self.AgentCount, seed=self.RNG.randint(0, 2**31-1))
self.AdjustNow = Bernoulli(self.AdjustPrb, seed=self.RNG.randint(0, 2**31-1)).draw(self.AgentCount)


def getRfree(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ def test_simulation(self):

self.assertAlmostEqual(
np.mean(self.agent.history['mLvlNow']),
1.2063544810887799)
1.2043946738813716)
10 changes: 4 additions & 6 deletions HARK/ConsumptionSaving/tests/test_IndShockConsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def test_getShocks(self):
self.agent.getShocks()

self.assertEqual(self.agent.PermShkNow[0],
0.9686755529883603)
1.0427376294215103)
self.assertEqual(self.agent.PermShkNow[1],
1.0050166461586711)
0.9278094171517413)
self.assertEqual(self.agent.TranShkNow[0],
1.2093790234554653)
0.881761797501595)

def test_ConsIndShockSolverBasic(self):
LifecycleExample = IndShockConsumerType(
Expand Down Expand Up @@ -102,13 +102,11 @@ def test_simulated_values(self):
self.agent.initializeSim()
self.agent.simulate()

print(self.agent.aLvlNow)

self.assertAlmostEqual(self.agent.MPCnow[1],
0.5711503906043797)

self.assertAlmostEqual(self.agent.aLvlNow[1],
0.21251164208206255)
0.18438326264597635)


class testBufferStock(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions HARK/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def addDiscreteOutcome(distribution, x, p, sort = False):

return DiscreteDistribution(pmf,X)

def combineIndepDstns(*distributions):
def combineIndepDstns(*distributions, seed=0):
'''
Given n lists (or tuples) whose elements represent n independent, discrete
probability spaces (probabilities and values), construct a joint pmf over
Expand Down Expand Up @@ -897,4 +897,4 @@ def combineIndepDstns(*distributions):
P_out = np.prod(np.array(P_temp),axis=0)

assert np.isclose(np.sum(P_out),1),'Probabilities do not sum to 1!'
return DiscreteDistribution(P_out, X_out)
return DiscreteDistribution(P_out, X_out, seed = seed)