24
24
from HARK import AgentType , Solution , NullFunc , HARKobject
25
25
from HARK .utilities import warnings # Because of "patch" to warnings modules
26
26
from HARK .interpolation import CubicInterp , LowerEnvelope , LinearInterp
27
- from HARK .simulation import drawDiscrete , drawLognormal , drawUniform
28
- from HARK .utilities import approxMeanOneLognormal , addDiscreteOutcomeConstantMean ,\
29
- combineIndepDstns , makeGridExpMult , CRRAutility , CRRAutilityP , \
27
+ from HARK .simulation import drawLognormal , drawUniform
28
+ from HARK .distribution import DiscreteDistribution , approxMeanOneLognormal , addDiscreteOutcomeConstantMean , combineIndepDstns
29
+ from HARK . utilities import makeGridExpMult , CRRAutility , CRRAutilityP , \
30
30
CRRAutilityPP , CRRAutilityP_inv , CRRAutility_invP , CRRAutility_inv , \
31
31
CRRAutilityP_invP
32
32
@@ -768,11 +768,10 @@ def setAndUpdateValues(self,solution_next,IncomeDstn,LivPrb,DiscFac):
768
768
----------
769
769
solution_next : ConsumerSolution
770
770
The solution to next period's one period problem.
771
- IncomeDstn : [np.array]
772
- A list containing three arrays of floats, representing a discrete
773
- approximation to the income process between the period being solved
774
- and the one immediately following (in solution_next). Order: event
775
- probabilities, permanent shocks, transitory shocks.
771
+ IncomeDstn : distribution.DiscreteDistribution
772
+ A DiscreteDistribution with a pmf
773
+ and two point value arrays in X, order:
774
+ permanent shocks, transitory shocks.
776
775
LivPrb : float
777
776
Survival probability; likelihood of being alive at the beginning of
778
777
the succeeding period.
@@ -783,10 +782,13 @@ def setAndUpdateValues(self,solution_next,IncomeDstn,LivPrb,DiscFac):
783
782
-------
784
783
None
785
784
'''
785
+ if isinstance (IncomeDstn , list ):
786
+ import pdb ; pdb .set_trace ()
787
+
786
788
self .DiscFacEff = DiscFac * LivPrb # "effective" discount factor
787
- self .ShkPrbsNext = IncomeDstn [ 0 ]
788
- self .PermShkValsNext = IncomeDstn [ 1 ]
789
- self .TranShkValsNext = IncomeDstn [ 2 ]
789
+ self .ShkPrbsNext = IncomeDstn . pmf
790
+ self .PermShkValsNext = IncomeDstn . X [ 0 ]
791
+ self .TranShkValsNext = IncomeDstn . X [ 1 ]
790
792
self .PermShkMinNext = np .min (self .PermShkValsNext )
791
793
self .TranShkMinNext = np .min (self .TranShkValsNext )
792
794
self .vPfuncNext = solution_next .vPfunc
@@ -2157,11 +2159,12 @@ def getShocks(self):
2157
2159
if N > 0 :
2158
2160
IncomeDstnNow = self .IncomeDstn [t - 1 ] # set current income distribution
2159
2161
PermGroFacNow = self .PermGroFac [t - 1 ] # and permanent growth factor
2160
- Indices = np .arange (IncomeDstnNow [0 ].size ) # just a list of integers
2161
2162
# Get random draws of income shocks from the discrete distribution
2162
- EventDraws = drawDiscrete (N ,X = Indices ,P = IncomeDstnNow [0 ],exact_match = False ,seed = self .RNG .randint (0 ,2 ** 31 - 1 ))
2163
- PermShkNow [these ] = IncomeDstnNow [1 ][EventDraws ]* PermGroFacNow # permanent "shock" includes expected growth
2164
- TranShkNow [these ] = IncomeDstnNow [2 ][EventDraws ]
2163
+ EventDraws = IncomeDstnNow .draw_events (N ,
2164
+ seed = self .RNG .randint (0 ,2 ** 31 - 1 ))
2165
+
2166
+ PermShkNow [these ] = IncomeDstnNow .X [0 ][EventDraws ]* PermGroFacNow # permanent "shock" includes expected growth
2167
+ TranShkNow [these ] = IncomeDstnNow .X [1 ][EventDraws ]
2165
2168
2166
2169
# That procedure used the *last* period in the sequence for newborns, but that's not right
2167
2170
# Redraw shocks for newborns, using the *first* period in the sequence. Approximation.
@@ -2170,11 +2173,12 @@ def getShocks(self):
2170
2173
these = newborn
2171
2174
IncomeDstnNow = self .IncomeDstn [0 ] # set current income distribution
2172
2175
PermGroFacNow = self .PermGroFac [0 ] # and permanent growth factor
2173
- Indices = np . arange ( IncomeDstnNow [ 0 ]. size ) # just a list of integers
2176
+
2174
2177
# Get random draws of income shocks from the discrete distribution
2175
- EventDraws = drawDiscrete (N ,X = Indices ,P = IncomeDstnNow [0 ],exact_match = False ,seed = self .RNG .randint (0 ,2 ** 31 - 1 ))
2176
- PermShkNow [these ] = IncomeDstnNow [1 ][EventDraws ]* PermGroFacNow # permanent "shock" includes expected growth
2177
- TranShkNow [these ] = IncomeDstnNow [2 ][EventDraws ]
2178
+ EventDraws = IncomeDstnNow .draw_events (N ,
2179
+ seed = self .RNG .randint (0 ,2 ** 31 - 1 ))
2180
+ PermShkNow [these ] = IncomeDstnNow .X [0 ][EventDraws ]* PermGroFacNow # permanent "shock" includes expected growth
2181
+ TranShkNow [these ] = IncomeDstnNow .X [1 ][EventDraws ]
2178
2182
# PermShkNow[newborn] = 1.0
2179
2183
TranShkNow [newborn ] = 1.0
2180
2184
@@ -2375,7 +2379,8 @@ def checkFVAC(self,verbose,public_call):
2375
2379
Evaluate and report on the Finite Value of Autarky Condition
2376
2380
Hyperlink to paper: [url]/#Autarky-Value
2377
2381
'''
2378
- EpShkuInv = np .dot (self .PermShkDstn [0 ][0 ],self .PermShkDstn [0 ][1 ]** (1 - self .CRRA ))
2382
+ EpShkuInv = np .dot (self .PermShkDstn [0 ].pmf ,
2383
+ self .PermShkDstn [0 ].X ** (1 - self .CRRA ))
2379
2384
if self .CRRA != 1.0 :
2380
2385
uInvEpShkuInv = EpShkuInv ** (1 / (1 - self .CRRA )) # The term that gives a utility-consequence-adjusted utility growth
2381
2386
else :
@@ -2431,8 +2436,9 @@ def checkConditions(self,verbose=False,public_call=True):
2431
2436
# [url]/#Uncertainty-Modified-Conditions
2432
2437
2433
2438
self .InvPermShkDstn = deepcopy (self .PermShkDstn )
2434
- self .InvPermShkDstn [0 ][1 ]= 1 / self .PermShkDstn [0 ][1 ]
2435
- EPermShkInv = np .dot (self .InvPermShkDstn [0 ][0 ],1 / self .PermShkDstn [0 ][1 ]) # $\Ex_{t}[\psi^{-1}_{t+1}]$ (in first eqn in sec)
2439
+ self .InvPermShkDstn [0 ].X = 1 / self .PermShkDstn [0 ].X
2440
+ EPermShkInv = np .dot (self .InvPermShkDstn [0 ].pmf ,
2441
+ 1 / self .PermShkDstn [0 ].X ) # $\Ex_{t}[\psi^{-1}_{t+1}]$ (in first eqn in sec)
2436
2442
2437
2443
InvEPermShkInv = (1 / EPermShkInv ) # $\underline{\psi}$ in the paper (\bar{\isp} in private version)
2438
2444
PermGroFacAdj = self .PermGroFac [0 ]* InvEPermShkInv # [url]/#PGroAdj
@@ -2782,7 +2788,9 @@ def constructLognormalIncomeProcessUnemployment(parameters):
2782
2788
PermShkValsRet = np .array ([1.0 ])
2783
2789
TranShkValsRet = np .array ([1.0 ])
2784
2790
ShkPrbsRet = np .array ([1.0 ])
2785
- IncomeDstnRet = [ShkPrbsRet ,PermShkValsRet ,TranShkValsRet ]
2791
+ IncomeDstnRet = DiscreteDistribution (ShkPrbsRet ,
2792
+ [PermShkValsRet ,
2793
+ TranShkValsRet ])
2786
2794
2787
2795
# Loop to fill in the list of IncomeDstn random variables.
2788
2796
for t in range (T_cycle ): # Iterate over all periods, counting forward
0 commit comments