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

fix examples #945

Merged
merged 2 commits into from
Feb 11, 2021
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
4 changes: 2 additions & 2 deletions HARK/ConsumptionSaving/ConsLaborModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def getControls(self):
) # Assign labor supply
self.controls['cNrm'] = cNrmNow
self.MPCnow = MPCnow
self.controls['LbrNow'] = LbrNow
self.controls['Lbr'] = LbrNow

def getPostStates(self):
"""
Expand All @@ -530,7 +530,7 @@ def getPostStates(self):
these = t == self.t_cycle
mNrmNow[these] = (
self.state_now['bNrm'][these]
+ self.controls['LbrNow'][these] * self.shocks['TranShk'][these]
+ self.controls['Lbr'][these] * self.shocks['TranShk'][these]
) # mNrm = bNrm + yNrm
aNrmNow[these] = mNrmNow[these] - self.controls['cNrm'][these] # aNrm = mNrm - cNrm
self.state_now['mNrm'] = mNrmNow
Expand Down
231 changes: 231 additions & 0 deletions examples/ConsIndShockModel/Finite Cyclical Test.ipynb

Large diffs are not rendered by default.

144 changes: 28 additions & 116 deletions examples/ConsIndShockModel/IndShockConsumerType.ipynb

Large diffs are not rendered by default.

89 changes: 69 additions & 20 deletions examples/ConsIndShockModel/KinkedRconsumerType.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/ConsIndShockModel/KinkedRconsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# format_version: '1.2'
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3
# display_name: econ-ark-3.8
# language: python
# name: python3
# name: econ-ark-3.8
# ---

# %% [markdown]
Expand Down Expand Up @@ -214,7 +214,7 @@
# Now let's plot the distribution of (normalized) assets $a_t$ for the current population, after simulating for $500$ periods; this should be fairly close to the long run distribution:

# %%
plt.plot(np.sort(KinkyExample.state_now['aNrmNow']), np.linspace(0.0, 1.0, KinkyExample.AgentCount))
plt.plot(np.sort(KinkyExample.state_now['aNrm']), np.linspace(0.0, 1.0, KinkyExample.AgentCount))
plt.xlabel("End-of-period assets")
plt.ylabel("Cumulative distribution")
plt.ylim(-0.01, 1.01)
Expand Down
62 changes: 46 additions & 16 deletions examples/ConsIndShockModel/PerfForesightConsumerType.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/ConsIndShockModel/PerfForesightConsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# format_version: '1.2'
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3.7 econ-ark
# display_name: econ-ark-3.8
# language: python
# name: econ-ark
# name: econ-ark-3.8
# ---

# %% [markdown]
Expand Down Expand Up @@ -285,10 +285,12 @@
# %% pycharm= {"name": "#%%\n"}
PFexample.initializeSim()
PFexample.simulate(80)
PFexample.state_prev['aNrmNow'] += -5.0 # Adjust all simulated consumers' assets downward by 5
PFexample.state_prev['aNrm'] += -5.0 # Adjust all simulated consumers' assets downward by 5
PFexample.simulate(40)

plt.plot(np.mean(PFexample.history['mNrm'], axis=1))
plt.xlabel("Time")
plt.ylabel("Mean normalized market resources")
plt.show()

# %%
247 changes: 164 additions & 83 deletions examples/ConsumptionSaving/example_ConsAggShockModel.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/ConsumptionSaving/example_ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def mystr(number):
if solve_markov_micro or solve_markov_market or solve_krusell_smith:
# Make a Markov aggregate shocks consumer type
AggShockMrkvExample = AggShockMarkovConsumerType()
AggShockMrkvExample.IncomeDstn[0] = 2 * [AggShockMrkvExample.IncomeDstn[0]]
AggShockMrkvExample.IncShkDstn[0] = 2 * [AggShockMrkvExample.IncShkDstn[0]]
AggShockMrkvExample.cycles = 0

# Make a Cobb-Douglas economy for the agents
Expand Down Expand Up @@ -167,7 +167,7 @@ def mystr(number):
# Make a Krusell-Smith agent type
# NOTE: These agents aren't exactly like KS, as they don't have serially correlated unemployment
KSexampleType = deepcopy(AggShockMrkvExample)
KSexampleType.IncomeDstn[0] = [
KSexampleType.IncShkDstn[0] = [
DiscreteDistribution(
np.array([0.96, 0.04]),
[ np.array([1.0, 1.0]), np.array([1.0 / 0.96, 0.0])]
Expand Down Expand Up @@ -228,7 +228,7 @@ def mystr(number):
PolyStateExample = AggShockMarkovConsumerType()
PolyStateExample.MrkvArray = PolyMrkvArray
PolyStateExample.PermGroFacAgg = PermGroFacAgg
PolyStateExample.IncomeDstn[0] = StateCount * [PolyStateExample.IncomeDstn[0]]
PolyStateExample.IncShkDstn[0] = StateCount * [PolyStateExample.IncShkDstn[0]]
PolyStateExample.cycles = 0

# Make a Cobb-Douglas economy for the agents
Expand Down Expand Up @@ -263,3 +263,5 @@ def mystr(number):
+ str(t_end - t_start)
+ " seconds."
)


42 changes: 21 additions & 21 deletions examples/ConsumptionSaving/example_ConsGenIncProcessModel.ipynb

Large diffs are not rendered by default.

90 changes: 39 additions & 51 deletions examples/ConsumptionSaving/example_ConsIndShock.ipynb

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions examples/ConsumptionSaving/example_ConsLaborModel.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/ConsumptionSaving/example_ConsLaborModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# format_version: '1.4'
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3
# display_name: econ-ark-3.8
# language: python
# name: python3
# name: econ-ark-3.8
# language_info:
# codemirror_mode:
# name: ipython
Expand All @@ -22,7 +22,7 @@
# name: python
# nbconvert_exporter: python
# pygments_lexer: ipython3
# version: 3.6.9
# version: 3.8.7
# ---

from HARK.ConsumptionSaving.ConsLaborModel import (
Expand Down Expand Up @@ -129,7 +129,7 @@
if do_simulation:
t_start = process_time()
LaborIntMargExample.T_sim = 120 # Set number of simulation periods
LaborIntMargExample.track_vars = ["bNrmNow", 'cNrm']
LaborIntMargExample.track_vars = ["bNrm", 'cNrm']
LaborIntMargExample.initializeSim()
LaborIntMargExample.simulate()
t_end = process_time()
Expand All @@ -146,7 +146,7 @@
N = LaborIntMargExample.AgentCount
CDF = np.linspace(0.0, 1, N)

plt.plot(np.sort(LaborIntMargExample.cNrmNow), CDF)
plt.plot(np.sort(LaborIntMargExample.controls['cNrm']), CDF)
plt.xlabel(
"Consumption cNrm in " + str(LaborIntMargExample.T_sim) + "th simulated period"
)
Expand All @@ -155,7 +155,7 @@
plt.ylim(0.0, 1.0)
plt.show()

plt.plot(np.sort(LaborIntMargExample.LbrNow), CDF)
plt.plot(np.sort(LaborIntMargExample.controls['Lbr']), CDF)
plt.xlabel(
"Labor supply Lbr in " + str(LaborIntMargExample.T_sim) + "th simulated period"
)
Expand All @@ -164,7 +164,7 @@
plt.ylim(0.0, 1.0)
plt.show()

plt.plot(np.sort(LaborIntMargExample.state_now['aNrmNow']), CDF)
plt.plot(np.sort(LaborIntMargExample.state_now['aNrm']), CDF)
plt.xlabel(
"End-of-period assets aNrm in "
+ str(LaborIntMargExample.T_sim)
Expand Down
83 changes: 50 additions & 33 deletions examples/ConsumptionSaving/example_ConsMarkovModel.ipynb

Large diffs are not rendered by default.

96 changes: 75 additions & 21 deletions examples/ConsumptionSaving/example_ConsMedModel.ipynb

Large diffs are not rendered by default.

83 changes: 63 additions & 20 deletions examples/ConsumptionSaving/example_ConsPortfolioModel.ipynb

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions examples/ConsumptionSaving/example_ConsPrefShockModel.ipynb

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions examples/ConsumptionSaving/example_ConsRepAgentModel.ipynb

Large diffs are not rendered by default.

Loading