Skip to content

Commit

Permalink
more changes to prepare DemARKS for 0.10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Apr 16, 2020
1 parent 6535676 commit bc485d9
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 93 deletions.
36 changes: 19 additions & 17 deletions notebooks/Chinese-Growth.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/Chinese-Growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@

bottomDiscFac = 0.9800
topDiscFac = 0.9934
DiscFac_list = approxUniform(N=num_consumer_types,bot=bottomDiscFac,top=topDiscFac)[1]
DiscFac_list = approxUniform(N=num_consumer_types,bot=bottomDiscFac,top=topDiscFac).X

# Now, assign the discount factors we want to the ChineseConsumerTypes
for j in range(num_consumer_types):
Expand Down
39 changes: 5 additions & 34 deletions notebooks/IncExpectationExample.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/IncExpectationExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def runRoszypalSchlaffmanExperiment(CorrAct, CorrPcvd, DiscFac_center, DiscFac_s
ThisDict['PrstIncCorr'] = CorrAct

# Make a 7 point approximation to a uniform distribution of DiscFac
DiscFac_list = approxUniform(N=7,bot=DiscFac_center-DiscFac_spread,top=DiscFac_center+DiscFac_spread)[1]
DiscFac_list = approxUniform(N=7,bot=DiscFac_center-DiscFac_spread,top=DiscFac_center+DiscFac_spread).X

type_list = []
# Make a PersistentShockConsumerTypeX for each value of beta saved in DiscFac_list
Expand Down
4 changes: 2 additions & 2 deletions notebooks/KrusellSmith.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,13 @@
"outputs": [],
"source": [
"# Construct the distribution of types\n",
"from HARK.utilities import approxUniform\n",
"from HARK.distribution import approxUniform\n",
"\n",
"# Specify the distribution of the discount factor\n",
"num_types = 3 # number of types we want;\n",
"DiscFac_mean = 0.9858 # center of beta distribution \n",
"DiscFac_spread = 0.0085 # spread of beta distribution\n",
"DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread)[1]\n",
"DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread).X\n",
"BaselineType = deepcopy(KSAgent)\n",
"\n",
"MyTypes = [] # initialize an empty list to hold our consumer types\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/KrusellSmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,13 @@ def in_ipynb():

# %% {"code_folding": []}
# Construct the distribution of types
from HARK.utilities import approxUniform
from HARK.distribution import approxUniform

# Specify the distribution of the discount factor
num_types = 3 # number of types we want;
DiscFac_mean = 0.9858 # center of beta distribution
DiscFac_spread = 0.0085 # spread of beta distribution
DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread)[1]
DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread).X
BaselineType = deepcopy(KSAgent)

MyTypes = [] # initialize an empty list to hold our consumer types
Expand Down
139 changes: 131 additions & 8 deletions notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# extension: .py
# format_name: percent
# format_version: '1.2'
# jupytext_version: 1.2.1
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3
# language: python
Expand Down Expand Up @@ -186,14 +186,14 @@ def in_ipynb():

# %%
# This cell constructs seven instances of IndShockConsumerType with different discount factors
from HARK.utilities import approxUniform
from HARK.distribution import approxUniform
BaselineType = IndShockConsumerType(**cstwMPC_calibrated_parameters)

# Specify the distribution of the discount factor
num_types = 7 # number of types we want
DiscFac_mean = 0.9855583 # center of beta distribution
DiscFac_spread = 0.0085 # spread of beta distribution
DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread)[1]
DiscFac_dstn = approxUniform(num_types, DiscFac_mean-DiscFac_spread, DiscFac_mean+DiscFac_spread).X

MyTypes = [] # initialize an empty list to hold our consumer types
for nn in range(num_types):
Expand Down
20 changes: 10 additions & 10 deletions notebooks/Nondurables-During-Great-Recession.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/Nondurables-During-Great-Recession.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
# Calibrations from cstwMPC
bottomDiscFac = 0.9800
topDiscFac = 0.9934
DiscFac_list = approxUniform(N=num_consumer_types,bot=bottomDiscFac,top=topDiscFac)[1]
DiscFac_list = approxUniform(N=num_consumer_types,bot=bottomDiscFac,top=topDiscFac).X

# Now, assign the discount factors
for j in range(num_consumer_types):
Expand Down
130 changes: 117 additions & 13 deletions notebooks/Structural-Estimates-From-Empirical-MPCs-Fagereng-et-al.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"code_folding": [
0
Expand All @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"code_folding": [
0
Expand All @@ -61,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"code_folding": [
0
Expand All @@ -81,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"code_folding": [
0
Expand All @@ -104,7 +104,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"code_folding": [
0
Expand All @@ -123,7 +123,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"code_folding": [
0
Expand All @@ -138,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"code_folding": [
0
Expand All @@ -158,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"code_folding": [
0
Expand Down Expand Up @@ -190,7 +190,7 @@
" Euclidean distance between simulated MPCs and (adjusted) Table 9 MPCs.\n",
" '''\n",
" # Give our consumer types the requested discount factor distribution\n",
" beta_set = approxUniform(N=TypeCount,bot=center-spread,top=center+spread)[1]\n",
" beta_set = approxUniform(N=TypeCount,bot=center-spread,top=center+spread).X\n",
" for j in range(TypeCount):\n",
" EstTypeList[j](DiscFac = beta_set[j])\n",
"\n",
Expand Down Expand Up @@ -256,13 +256,117 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"code_folding": [
0
]
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.92 0.03 1.1274854942184123\n",
"0.9660000000000001 0.03 1.8595059870322312\n",
"0.92 0.0315 1.1283488603479197\n",
"0.874 0.0315 0.778255871453904\n",
"0.8280000000000001 0.03225 0.6819825156919915\n",
"0.8280000000000002 0.03075 0.6835548812203114\n",
"0.7360000000000001 0.033 0.7922890441302506\n",
"0.782 0.03225 0.7016715189874164\n",
"0.8740000000000001 0.03075 0.7788170641661598\n",
"0.805 0.031875 0.6805742675552975\n",
"0.8049999999999998 0.033375 0.6787844220096427\n",
"0.7934999999999997 0.03468750000000001 0.6852355238234841\n",
"0.7819999999999998 0.033 0.700889842861641\n",
"0.8165 0.0324375 0.677362729820926\n",
"0.8164999999999997 0.033937499999999995 0.6757164456766519\n",
"0.8222499999999997 0.03496874999999999 0.6758511425548946\n",
"0.8279999999999997 0.03299999999999999 0.6811133592390257\n",
"0.8107499999999999 0.03328125 0.676894640632367\n",
"0.8107499999999996 0.03478124999999999 0.6750631689086809\n",
"0.8078749999999992 0.03595312499999999 0.6744239196038181\n",
"0.8136249999999989 0.036609374999999986 0.6724284249651289\n",
"0.8150624999999985 0.03827343749999998 0.6703322941257293\n",
"0.806437499999998 0.04028906249999997 0.6692403829292708\n",
"0.8014062499999974 0.043464843749999954 0.6673189410747502\n",
"0.8085937499999967 0.045785156249999945 0.6604269189061285\n",
"0.8089531249999955 0.05070117187499992 0.65272712055137\n",
"0.7952968749999945 0.0558925781249999 0.6531048166528524\n",
"0.8028437499999925 0.06312890624999987 0.6352275674142442\n",
"0.8035624999999902 0.07296093749999982 0.6174053756797356\n",
"0.8172187499999912 0.06776953124999985 0.623279644640036\n",
"0.8118281249999859 0.09002929687499975 0.5843314701962605\n",
"0.813265624999981 0.10969335937499966 0.5516622208832312\n",
"0.79960937499998 0.11488476562499964 0.5453880007399536\n",
"0.7908046874999743 0.13844238281249954 0.5163269956570604\n",
"0.8005078124999652 0.17517480468749938 0.5499092597796972\n",
"0.7780468749999585 0.20392382812499923 0.5813614142333464\n",
"0.8044609374999754 0.13325097656249957 0.5202086128131443\n",
"0.7947578124999846 0.09651855468749973 0.5805560040839527\n",
"0.7990703124999701 0.15551074218749947 0.5060419354103581\n",
"0.785414062499969 0.16070214843749947 0.5034386878700592\n",
"0.775890624999966 0.17442773437499942 0.5149023099777296\n",
"0.7936796874999648 0.17777050781249937 0.5315857186141032\n",
"0.791523437499972 0.1482744140624995 0.5061530602276895\n",
"0.7929609374999671 0.1679384765624994 0.5082715311300752\n",
"0.7918828124999708 0.15319042968749946 0.5033949436309413\n",
"0.7782265624999698 0.15838183593749947 0.512748835721533\n",
"0.7938593749999701 0.15622851562499945 0.5028877731574135\n",
"0.8003281249999719 0.14871679687499945 0.5068348206273852\n",
"0.7891425781249697 0.15770581054687446 0.502519441768042\n",
"0.7911191406249689 0.16074389648437443 0.5022974415782882\n",
"0.7907373046874677 0.1645206298828119 0.5032698407410588\n",
"0.7864023437499685 0.1622211914062494 0.5027664061147642\n",
"0.7882666015624689 0.16072302246093692 0.502198620174269\n",
"0.7902431640624681 0.16376110839843686 0.5026328874780666\n",
"0.7894177246093443 0.15921963500976505 0.5021703660917155\n",
"0.7865651855468443 0.15919876098632751 0.5030573631478745\n",
"0.7899806518554378 0.1603576126098627 0.502160531034932\n",
"0.7911317749023132 0.15885422515869083 0.5022769519932859\n",
"0.78898289489743 0.1602558231353754 0.502180579074867\n",
"0.7904154815673521 0.15932142448425235 0.5021833317477105\n",
"0.7893410415649105 0.16002222347259465 0.5021165086178974\n",
"0.7899039688110039 0.1611602010726923 0.5021112183082238\n",
"0.7901470909118338 0.16213048410415593 0.5022990867023371\n",
"0.7892643585204766 0.16082481193542425 0.502159403561549\n",
"0.7894434318542168 0.16070801210403385 0.5021404531991109\n",
"0.7898015785216975 0.1604744124412531 0.50213329203524\n",
"0.7897120418548274 0.16053281235694827 0.5021302497927074\n",
"0.789532968521087 0.16064961218833868 0.5021304652782825\n",
"0.7896672735213923 0.1605620123147959 0.502126210894908\n",
"0.789577736854522 0.16062041223049106 0.5021314791648644\n",
"0.7896448893546748 0.16057661229371967 0.5021356844024427\n",
"0.7896225051879572 0.16059121227264347 0.5021256061827057\n",
"0.7897856211661981 0.1608611066937441 0.5021324277978072\n",
"0.7897408528327629 0.16089030665159165 0.5021362355798749\n",
"0.7897744290828392 0.16086840668320598 0.5021389064710859\n",
"0.7897632369994805 0.16087570667266787 0.502129658550051\n",
"0.7898447949886009 0.1610106538832182 0.5021074951519786\n",
"0.7899855268001243 0.1612951482832426 0.5021245728056754\n",
"0.7899299543499633 0.16119028788059891 0.5021135412553295\n",
"0.7898188094496416 0.16098056707531155 0.5021025392131131\n",
"0.7897632369994805 0.16087570667266787 0.502129658550051\n",
"0.7897596356272387 0.16083101988583742 0.5021341894826656\n",
"0.7898678855150626 0.16107790577597858 0.5021133757712383\n",
"0.7898318022191213 0.16099561047926486 0.5021068384032057\n",
"0.7898613891303228 0.16107038407400193 0.5021036662483996\n",
"Optimization terminated successfully.\n",
" Current function value: 0.502103\n",
" Iterations: 41\n",
" Function evaluations: 85\n",
"Time to estimate is 188.1969873905182 seconds.\n",
"Finished estimating for scaling factor of 1.0 and \"splurge amount\" of $0.0\n",
"Optimal (beta,nabla) is [0.78981881 0.16098057], simulated MPCs are:\n",
"[[0.77361336 0.68317127 0.56461082 0.40476962]\n",
" [0.74354975 0.66482752 0.55301552 0.39626053]\n",
" [0.70353353 0.63512154 0.5305429 0.3793119 ]\n",
" [0.5613238 0.50428804 0.4125933 0.29261249]]\n",
"Distance from Fagereng et al Table 9 is 0.5021025392131131\n"
]
}
],
"source": [
"# Conduct the estimation\n",
"\n",
Expand All @@ -277,7 +381,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -286,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def FagerengObjFunc(center,spread,verbose=False):
Euclidean distance between simulated MPCs and (adjusted) Table 9 MPCs.
'''
# Give our consumer types the requested discount factor distribution
beta_set = approxUniform(N=TypeCount,bot=center-spread,top=center+spread)[1]
beta_set = approxUniform(N=TypeCount,bot=center-spread,top=center+spread).X
for j in range(TypeCount):
EstTypeList[j](DiscFac = beta_set[j])

Expand Down

0 comments on commit bc485d9

Please sign in to comment.