From 42a3d0a62554e5c33aef0ec50658f53f71310dcf Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 3 Jan 2020 17:54:00 -0500 Subject: [PATCH] Using default params in initializer for classes in ConsPrefShockModel --- HARK/ConsumptionSaving/ConsPrefShockModel.py | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/HARK/ConsumptionSaving/ConsPrefShockModel.py b/HARK/ConsumptionSaving/ConsPrefShockModel.py index 636c8c3dd..b1d0c4d6f 100644 --- a/HARK/ConsumptionSaving/ConsPrefShockModel.py +++ b/HARK/ConsumptionSaving/ConsPrefShockModel.py @@ -15,6 +15,7 @@ from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType, ConsumerSolution, ConsIndShockSolver, \ ValueFunc, MargValueFunc, KinkedRconsumerType, ConsKinkedRsolver from HARK.interpolation import LinearInterpOnInterp1D, LinearInterp, CubicInterp, LowerEnvelope +import HARK.ConsumptionSaving.ConsumerParameters as Params class PrefShockConsumerType(IndShockConsumerType): ''' @@ -23,7 +24,10 @@ class PrefShockConsumerType(IndShockConsumerType): ''' shock_vars_ = IndShockConsumerType.shock_vars_ + ['PrefShkNow'] - def __init__(self,cycles=1,time_flow=True,**kwds): + def __init__(self, + cycles=1, + time_flow=True, + **kwds): ''' Instantiate a new ConsumerType with given data, and construct objects to be used during solution (income distribution, assets grid, etc). @@ -41,7 +45,14 @@ def __init__(self,cycles=1,time_flow=True,**kwds): ------- None ''' - IndShockConsumerType.__init__(self,cycles=cycles,time_flow=time_flow,**kwds) + params = Params.init_preference_shocks.copy() + params.update(kwds) + kwds = params + + IndShockConsumerType.__init__(self, + cycles=cycles, + time_flow=time_flow, + **kwds) self.solveOnePeriod = solveConsPrefShock # Choose correct solver def preSolve(self): @@ -206,6 +217,9 @@ def __init__(self,cycles=1,time_flow=True,**kwds): ------- None ''' + params = Params.init_kinky_pref.copy() + params.update(kwds) + kwds = params IndShockConsumerType.__init__(self,**kwds) self.solveOnePeriod = solveConsKinkyPref # Choose correct solver self.addToTimeInv('Rboro','Rsave') @@ -600,7 +614,6 @@ def solveConsKinkyPref(solution_next,IncomeDstn,PrefShkDstn, ############################################################################### def main(): - import HARK.ConsumptionSaving.ConsumerParameters as Params import matplotlib.pyplot as plt from HARK.utilities import plotFuncs from time import clock @@ -609,7 +622,7 @@ def main(): do_simulation = True # Make and solve a preference shock consumer - PrefShockExample = PrefShockConsumerType(**Params.init_preference_shocks) + PrefShockExample = PrefShockConsumerType() PrefShockExample.cycles = 0 # Infinite horizon t_start = clock() @@ -652,7 +665,7 @@ def main(): ########################################################################### # Make and solve a "kinky preferece" consumer, whose model combines KinkedR and PrefShock - KinkyPrefExample = KinkyPrefConsumerType(**Params.init_kinky_pref) + KinkyPrefExample = KinkyPrefConsumerType() KinkyPrefExample.cycles = 0 # Infinite horizon t_start = clock()