Skip to content

Commit

Permalink
Merge pull request #316 from iworld1991/BayerLuetticke
Browse files Browse the repository at this point in the history
zoom june17
  • Loading branch information
llorracc authored Jun 17, 2019
2 parents 1604072 + fb10d97 commit a19f6bc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
36 changes: 18 additions & 18 deletions HARK/BayerLuetticke/DCT-Copula-Illustration.ipynb

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions HARK/BayerLuetticke/TwoAsset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
"os.chdir(code_dir) # Go to the directory with pickled code\n",
"\n",
"## EX3SS_20.p is the information in the stationary equilibrium (20: the number of illiquid and liquid weath grids )\n",
"EX3SS=pickle.load(open(\"EX3SS_20.p\", \"rb\"))"
"EX3SS=pickle.load(open(\"EX3SS_20.p\", \"rb\"))\n",
"\n",
"## WangTao: Find the code that generates this"
]
},
{
Expand Down Expand Up @@ -345,9 +347,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"code_folding": [
0
],
"code_folding": [],
"lines_to_end_of_cell_marker": 0,
"lines_to_next_cell": 1
},
Expand Down Expand Up @@ -390,7 +390,7 @@
" # c = invmarg(marg(c)), so first bit gets consumption policy function\n",
" Yss=np.asmatrix(np.concatenate((invmutil(self.mutil_c.copy().flatten(order = 'F')),\\\n",
" invmutil(self.Vk.copy().flatten(order = 'F')),\n",
" [np.log(self.par['Q'])], # Question: Price of the illiquid asset, right?\n",
" [np.log(self.par['Q'])], # Price of the illiquid asset\n",
" [ np.log(self.par['PI'])], # Inflation\n",
" [ np.log(self.Output)], \n",
" [np.log(self.par['G'])], # Gov spending\n",
Expand All @@ -409,7 +409,7 @@
" # nh = number of gridpoints for human capital (pty)\n",
" Gamma_state = np.zeros( # Create zero matrix of size [nm + nk + nh,nm + nk + nh - 4]\n",
" (self.mpar['nm']+self.mpar['nk']+self.mpar['nh'],\n",
" self.mpar['nm']+self.mpar['nk']+self.mpar['nh'] - 4)) # Question: Why 4?\n",
" self.mpar['nm']+self.mpar['nk']+self.mpar['nh'] - 4)) # Question: Why 4? WangTao: Find SC's answer\n",
"\n",
" # Impose adding-up conditions: \n",
" # In each of the block matrices, probabilities must add to 1\n",
Expand All @@ -420,6 +420,7 @@
" Gamma_state[j,j]=Gamma_state[j,j] - np.sum(Gamma_state[0:self.mpar['nm'],j])\n",
" bb = self.mpar['nm'] # Question: bb='bottom base'? because bb shorter to type than self.mpar['nm'] everywhere\n",
"\n",
" # WangTao: Replace magic numbers or obscure variables with more self-explanatory names\n",
" for j in range(self.mpar['nk']-1):\n",
" Gamma_state[bb+np.arange(0,self.mpar['nk'],1), bb+j-1] = -np.squeeze(Xss[bb+np.arange(0,self.mpar['nk'],1)])\n",
" Gamma_state[bb+j,bb-1+j] = 1. - Xss[bb+j] \n",
Expand Down Expand Up @@ -489,9 +490,9 @@
" while linalg.norm(XX[ind[:i]].copy())/linalg.norm(XX) < level:\n",
" i += 1 \n",
" \n",
" needed = i # Question:Isn't this counting the ones that are NOT needed?\n",
" needed = i # The points that are kept\n",
" \n",
" index_reduced = np.sort(ind[:i]) # Retrieve the good \n",
" index_reduced = np.sort(ind[:i]) # Retrieve the good ones\n",
" \n",
" return index_reduced"
]
Expand Down Expand Up @@ -2275,7 +2276,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
13 changes: 8 additions & 5 deletions HARK/BayerLuetticke/TwoAsset.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def in_ipynb():
## EX3SS_20.p is the information in the stationary equilibrium (20: the number of illiquid and liquid weath grids )
EX3SS=pickle.load(open("EX3SS_20.p", "rb"))

## WangTao: Find the code that generates this


# -

Expand Down Expand Up @@ -277,7 +279,7 @@ def in_ipynb():
# \end{array}\right.
# \end{equation}

# + {"code_folding": [0]}
# + {"code_folding": []}
## State reduction and Discrete cosine transformation

class StateReduc_Dct:
Expand Down Expand Up @@ -315,7 +317,7 @@ def StateReduc(self):
# c = invmarg(marg(c)), so first bit gets consumption policy function
Yss=np.asmatrix(np.concatenate((invmutil(self.mutil_c.copy().flatten(order = 'F')),\
invmutil(self.Vk.copy().flatten(order = 'F')),
[np.log(self.par['Q'])], # Question: Price of the illiquid asset, right?
[np.log(self.par['Q'])], # Price of the illiquid asset
[ np.log(self.par['PI'])], # Inflation
[ np.log(self.Output)],
[np.log(self.par['G'])], # Gov spending
Expand All @@ -334,7 +336,7 @@ def StateReduc(self):
# nh = number of gridpoints for human capital (pty)
Gamma_state = np.zeros( # Create zero matrix of size [nm + nk + nh,nm + nk + nh - 4]
(self.mpar['nm']+self.mpar['nk']+self.mpar['nh'],
self.mpar['nm']+self.mpar['nk']+self.mpar['nh'] - 4)) # Question: Why 4?
self.mpar['nm']+self.mpar['nk']+self.mpar['nh'] - 4)) # Question: Why 4? WangTao: Find SC's answer

# Impose adding-up conditions:
# In each of the block matrices, probabilities must add to 1
Expand All @@ -345,6 +347,7 @@ def StateReduc(self):
Gamma_state[j,j]=Gamma_state[j,j] - np.sum(Gamma_state[0:self.mpar['nm'],j])
bb = self.mpar['nm'] # Question: bb='bottom base'? because bb shorter to type than self.mpar['nm'] everywhere

# WangTao: Replace magic numbers or obscure variables with more self-explanatory names
for j in range(self.mpar['nk']-1):
Gamma_state[bb+np.arange(0,self.mpar['nk'],1), bb+j-1] = -np.squeeze(Xss[bb+np.arange(0,self.mpar['nk'],1)])
Gamma_state[bb+j,bb-1+j] = 1. - Xss[bb+j]
Expand Down Expand Up @@ -414,9 +417,9 @@ def do_dct(self, obj, mpar, level):
while linalg.norm(XX[ind[:i]].copy())/linalg.norm(XX) < level:
i += 1

needed = i # Question:Isn't this counting the ones that are NOT needed?
needed = i # The points that are kept

index_reduced = np.sort(ind[:i]) # Retrieve the good
index_reduced = np.sort(ind[:i]) # Retrieve the good ones

return index_reduced
# -
Expand Down

0 comments on commit a19f6bc

Please sign in to comment.