Reachable()
.
Users do not call this function.
Public methods | ||
CreateTheta | Called in CreateSpaces to set up Θ. | |
loop |
Public fields | ||
logf | static | File for logging data output. |
lognm | static | timestamped file name. |
Volume | static | Volume of output |
Public methods | ||
SetLog | static | Open data log with timestamp. |
Public fields | ||
Blocks | static | List of StateBlocks added to the model. |
Chi | static | list of AuxiliaryValues that depend on the current outcome. |
ClockType | static | category of clock. |
counter | static | counter variable. |
curREdensity | static | density of current group. |
delta | static | The discount factor δ. |
EOoE | static | task to integrate outcomes over \(\epsilon\). |
EStoS | static | task to update tomorrow's state distribution. |
ETT | static | task to compute endogenous transitions |
gdist | static | distriubution over groups |
IOE | static | task to integrate V over semi-exogenous states. |
L | static | Label for the problem. |
logf | static | file for diagnostic output. |
lognm | static | dated file name for diagnostic output |
MyVersion | static | Version of niqlow that code is written for. |
NKptrans | static | shared space for N-K iteration. |
NKvindex | static | |
NxtExog | static | Array of Exogenous next state indices and transitions. |
parents | static | List of parent classes. |
S | static | array of Spaces, using SubVectorNames as names for elements. |
SS | static | array of `SubSpaces . |
States | static | List of State Variables added to the model. |
SubVectors | static | List of variables by vector. |
tod | static | Outcomes sent to StateToStatePrediction |
tom | static | |
userState | static | copy of user's Bellman object used for cloning. |
Volume | static | Output level. |
XUT | static | task to compute utility over exogenous states. |
Public methods | ||
Actions | static | Add variables to the action vector \(\alpha\). |
AuxiliaryOutcomes | static | Add AuxiliaryValues to \(\chi\). |
CreateSpaces | static | Initialize all spaces. |
DrawFsamp | static | Draw a population count random sample of N values from the random effects distribution. |
DrawGroup | static | Draw γ from Γ according to the density. |
DrawOneExogenous | static | Draw one \(\epsilon\) vector given following \(P(\epsilon)\). |
EndogenousStates | static | Add StateVariables to the endogenous vector \(\theta\). |
ExogenousStates | static | Add StateVariables to the exogenous vector \(\epsilon\). |
GetAind | static | Return index into the feasible A list for a θ. |
GetPinf | static | Return \(P_\infty(\theta)\). |
GetPstar | static | Return choice probability for a \(\theta\) and current \(\gamma\). |
GetTrackTrans | static | Return tracking transition at a given \(\eta,\theta\) combination. |
GetUseEps | static | |
GroupVariables | static | Add TimeInvariants to the group vector \(\gamma\). |
Indicators | static | Create auxiliary values that are indicators for a state or action. |
Initialize | static | Initialize static members. |
Interactions | static | Create and return a list of auxiliary values for interactions. |
KLaggedAction | static | Create a K-array of lagged values of an action variable. |
KLaggedState | static | Create an K+1-array of a state variable and K lags of its values. |
MakeGroups | static | |
MultiInteractions | static | Create and return a list of auxiliary values for interactions. |
onlyDryRun | static | For debugging: Set a flag so that CreateSpaces does not actually create the space. |
RecomputeTrans | static | If changing fixed parameters and UpdateTime==WhenFlagIsSet then next Solve() will recompute transitions. |
SemiExogenousStates | static | Add StateVariables to the semiexogenous vector \(\eta\). |
SetClock | static | Set the model clock. |
SetDelta | static | Set the discount factor, \(\delta\). |
Settheta | static | Sets the current θ. |
SetUpdateTime | static | Tell DDP when parameters and transitions have to be updated. |
SetVersion | static | Checks the version number you send with the current version of niqlow. |
StorePalpha | static | Ask to store overall \(P*()\) choice probability matrix. |
SubSampleStates | static | Request that the State Space be subsampled for extrapolation methods such as KeaneWolpin. |
SyncAct | static | Ensure that ActionVariable current values (v ) is synched with the choice vector \(\alpha\). |
UpdateDistribution | static | |
ValuesCounters | static | Create an array of counters for different values of a state or action variable. |
Public fields | ||
div | static const | |
ndone | static | |
OutAll | static | |
prtfmt | static | |
prtfmt0 | static | |
rp | static | |
SimLabels | static | |
SVlabels | static | |
Vlabel0 | static | |
Public methods | ||
DPDebug | ||
outAllV | static | Print the table of value functions and choice probabilities for all fixed effect groups. |
outV | static | For the current fixed-effect group, print the value function \(EV(\theta)\) and choice probability \(P^\star(\alpha;\epsilon,\eta,\theta)\) or index of max \(P^\star\). |
Public fields | ||
s | ||
Public methods | ||
DumpExogTrans | Display the exogenous transition as a matrix. |
Public methods | ||
EndogTrans | ||
Transitions |
Public fields | ||
auxlist | static | |
chq | static | |
tmp | static | |
Public methods | ||
ExpectedOutcomes | Compute the expected values of tracked auxiliary variables over the exogenous vector ε |
Public fields | ||
AnyExog | const | indicate there are exogenous variabes so loop is required. |
U | stores Utility matrix for current \(\theta\). | |
Public methods | ||
Run |
Public methods | ||
~FETask |
DP.ox
.
MyModel
(the user's DP problem) defines a single decision
making process. So \(\Gamma\) would have a single element.MyModel
can include more than one problem to be solved by creating Groups.GroupVariables
must occur in the user's code between the call to
Initialize()
and CreateSpaces
.enum{male,female,Ngender} enum{lo,hi,Nability} Initialize(…); ⋮ GroupVariables( a = new RandomEffect("a",Nability), g = new FixedEffect("sex",Ngender), ); ⋮ CreateSpaces(…);
Public fields | ||
find | Index into fixed effects | |
mobj | method specific object. | |
Palpha | Expand Choice Prob matrix. | |
Pinfinity | Stationary distribution \(P_\infty\) for ergodic clock models. | |
pos | Position in \(\Gamma\). | |
Ptrans | State-to-State transition. | |
rind | Index into random effects | |
state | Group's state vector. | |
Public methods | ||
Density | Compute density of current group \(\gamma\) conditional on fixed effects. | |
DrawfromStationary | Draw \(\theta\) from \(P_\infty(\theta)\) for current \(\gamma\). | |
IncPtrans | ||
Reset | Reset a group. | |
StationaryDistribution | Compute the stationary distribution over reachable states, \(P_\infty(\theta)\). |
Public fields | ||
qtask | sub task. | |
span | const | |
Public methods | ||
~GroupTask |
Public methods | ||
SetGroup | Set the current group. |
Public methods | ||
picked | ||
SubSample | ||
SubSampleDone |
Public methods | ||
OutAuto |
Public fields | ||
flat | ||
L | cumulative likelihood or other outcome. | |
path | The path object I am processing. | |
Public methods | ||
Integrate | Integrate over \(\gamma_r\). | |
RandomEffectsIntegration | . |
Reachable()
.
If a subsampled state is now not sampled its stored information is destroyed (using Bellman::Delete
).
If a non-sampled state is now sampled its point in \(\theta\) is created.
Users do not call this directly.
Public methods | ||
ReSubSample |
Public fields | ||
fixl | const | |
fixr | const |
Public fields | ||
aM | const | |
MaxChoiceIndex | const | |
nottop | ||
r | ||
s | ||
stub | ||
ToScreen | const | |
TrimTerminals | const | |
TrimZeroChoice | const | |
Public methods | ||
SaveV | Save the value function as a matrix and/or print. |
Public fields | ||
AnyEta | const | indicate there are \(\eta\) variables so loop is required. |
CurrExogWidth | ||
Public methods | ||
Run | virtual |
Public fields | ||
C | cumulative product of N. | |
D | dimension of the space. | |
M | Min indices of var group in state vector. | |
N | # of values state variables take on. | |
size | product of VN over VM[] to VX[]. | |
X | maX indices of var group in state vector. | |
Public methods | ||
Append | ||
Space | Tracks information about a subvector of the state vector. |
Public fields | ||
ClockIndex | static | location of the clock object. |
D | # of dimensions | |
left | leftmost state index. | |
O | vector of offsets | |
right | rightmost state index | |
S | static | shared spaces |
size | # of elements | |
Public methods | ||
SubSpace | Tracks information about a set of one or more Spaces. | |
~SubSpace |
Public fields | ||
Slist |
Public fields | ||
Slist | ||
Public methods | ||
SVTrans |
state
member which is a vector of values at
the current point in the operation.loop()
iterates over the task's range of state variables,
defined by left
and right
indices into the state vector.loop()
the Task's Run() method is called.Run()
is a virtual method, so the Task's replacement is called inside the
shared loop()
method.Run()
method.loop()
is inherited from the parent class.Run()
method can in turn call the loop()
of an internally stored itask.FETasks
for which its
itask
is a RETask
if random effects are present
or a ThetaTask if not.Public fields | ||
caller | const | Task that called me (used by methods). |
d | index into state of current spanning dimension. | |
done | Indicates task is done (may require one more trip). | |
inner | keep going ... | |
itask | Inner task for a stack of tasks to perform. | |
iter | Times Run() called while in progress. | |
L | Label for debugging purposes. | |
left | const | leftmost variable in state to loop over |
MaxTrips | max number of outer trips | |
right | const | rightmost variable in state to loop over |
state | N×1 vector, current values of all states. | |
subspace | subspace to use for indexing during the task | |
trace | static | |
trips | Trips through the task's space. | |
Public methods | ||
list | virtual | Process a vector (list) of state indices. |
SyncStates | Ensure that all StateVariable objects v are synched with the internally stored state vector. |
|
~Task |
Traverse()
method will either loop
or list()
depending on whether the user
asked for the state space Θ to be processed according to a list of reachable
states or looping over all combinations of state variable values. This is done
with an arguement to Initialize().
... | ActionVariables to add to \(\alpha\) See Action Variables for more explanation. |
struct MyModel : Bellman { ⋮ static decl work; ⋮ } ⋮ Actions(work = new ActionVariable("w",2));
MyModel
then a no-choice action is added by CreateSpaces().
... | AuxiliaryValues or static function(s) that take no arugment, which will be sent to StaticAux or arrays of auxiliary variables and static functions to add to \(\chi\) |
α
, ζ and full state vectors have been set.
find | index of fixed group |
N | number of draws to take |
I::g
and syncs state variables in γ
aState | address of state vector to insert value |
... | StateVariables to add to \(\theta\) |
... | Exogenous StateVariables to add \(\epsilon\) |
i | index of θ in the state space Θ |
g | group index UseCurrent (default) |
i | tracking index of \(\theta\) in the state space \(\Theta\) |
Theta[i].pandv
)
i | index of \(\theta\) in the state space \(\Theta\) |
h | index of current \(\eta\) vector |
... | TimeInvariants to add to \(\gamma\) |
ivar | state variable or action variable to interact |
UseLabel: | use abbreviated ivar.L string: start of column labels for matching to data. |
ilo | minimum value of ivar to track interaction (default=0) |
ihi | maximum index to track (default = 100) For objects in data, tracked moment label must have the form prefix_kk |
userState | a Bellman-derived object that represents one point
\(\theta\) in the user's endogenous state space \(\Theta\). The Ox
clone() function is used to copy this object to fill out \(\Theta\).
This also allows userReachable() to be a virtual function
|
UseStateList | TRUE, traverse the state space \(\Theta\) from a list of reachable indices FALSE (default), traverse \(\Theta\) through iteration on all state variables |
MyModel
MUST call DPparent::Initialize
before adding any variables to the model.
UseStateList=TRUE may be much faster if the untrimmed state space is very large compared to the trimmed (reachable) state space.
ivar | state variable or action variable to interact |
olist | Unitialized, no interaction list of objects to interact with indicators for ivar |
UseLabel: | use abbreviated ivar.L string: start of column labels for matching to data. |
ilo | minimum value of ivar to track interaction (default=0) |
ihi | maximum index to track (default = 100) For objects in data, tracked moment label must have the form prefix_kk_xlabbrev kk: current (not actual) value of ivar with a leading 0 xlabbrev: abbreviated label of member of olist (max 4 characters) |
L | label |
Target | ActionVariable to track |
K | positive integer, number of lags to track |
Prune | TRUE [default] if clock is finite horizon, presume all lags initialize to 0 and prune unreachable values. |
d = new BinaryChoice("d"); status = KLaggedState(d,3); EndogenousStates(status);
L | label |
Target | StateVariable to track |
K | positive integer, number of lags to track |
Prune | TRUE [default] if clock is finite horizon, presume all lags initialize to 0 and prune unreachable values. |
status = KLaggedState(new Markov("q",<0.9,0.2;0.1,0.8>),3)); EndogenousStates(status);
ivar | state variable or action variable to interact |
olist | Unitialized, no interaction list of objects to interact with indicators for ivar |
UseLabel: | use abbreviated ivar.L string: start of column labels for matching to data. |
ilo | minimum value of ivar to track interaction (default=0) |
ihi | maximum index to track (default = 100) For objects in data, tracked moment label must have the form prefix_kk_xlabbrev kk: current (not actual) value of ivar with a leading 0 xlabbrev: abbreviated label of member of olist (max 4 characters) |
... | Semi-exogenous StateVariables to add to \(\eta\) |
ClockOrType | Clock derived state block integer, ClockTypes |
... | arguments to pass to constructor of clock type |
Initialize(Reachable); SetClock(InfiniteHorizon); ⋮ CreateSpaces();Finite Horizon
decl T=65; Initialize(Reachable); SetClock(NormalAging,T); ⋮ CreateSpaces();Early Mortaliy
MyModel::Pi(); SetClock(RandomMortality,T,MyModel::Pi); Initialize(Reachable); ⋮ CreateSpaces();
MyModel
can also create a derived Clock and pass it to SetClock.
endogind | tracking index of the state θ. |
time | UpdateTimes [default=AfterRandom] THe default allows for transitions that depend on dynamically determined parameters, and the current value of FixedEffect variables (if there are any), and RandomEffect variables (if there are any). |
⋮ SetUpdateTime(InCreateSpaces); //have to tell me before you call CreateSpaces! CreateSpaces();MyModel is still simpler than the default, but its transitions do depend on dynamic parameters (say an estimated parameter). So transitions have to be updated each time all solutions are initiated by Solve() and can't just be done in
CreateSpaces
.
⋮ CreateSpaces(); SetUpdateTime(OnlyOnce); // can be set after CreateSpacesMyModel is still simpler than the default, but its transitions do depend on the values of FixedEffects. RandomEffects do not affect transitions, only utility so transitions do not have to be updated with each change in random effects:
⋮ CreateSpaces(); SetUpdateTime(AfterFixed);
v | integer [default=200] |
SampleProportion | 0 < double ≤ 1.0, fixed subsample size across t N::T×1 vector, time-varying sampling proportions. [default] 1.0: do not subsample at all, visit each state. |
MinSZ | minimum number of states to sample each period [default=0] |
MaxSZ | maximum number of states to sample each period [default=INT_MAX, no maximum] |
N::T=4
SubSampleStates(<1.0;0.9;0.75;0.5>);This will sample half the states in the last period, 3/4 of the states in period 2, 90% in period 1 and all the states in period 0.
SubSampleStates(1.0,0,100);This will ensure that more than 100 states are subsampled each period. If there are fewer reachable states than 100 at
t
then all states are sampled and the solution is exact.
SubSampleStates(0.8,30,200);This will sample 80% of states at all periods, but it will guarantee that no fewer than 30 and no more than 200 are sampled in any one period.
CreateSpaces()
the subsampling actually occurs during
CreateSpaces().CreateSpaces()
then the new sampling scheme occurs immediately.
Storage for U and Ρ() is re-allocated accordingly.v
) is synched with the choice vector \(\alpha\).
a | action vector. |
L | label |
Target | StateVariable or ActionVariable to track with N-1 values |
MaxCounts | N-vector where 0 means do not track that value. In this case, the corresponding state is Fixed M>0, max count to keep. |
Prune | TRUE [default] if clock is finite horizon, then all but the last will be set as not PRUNED; the first counted value will be a special state counter that stores the array and checks reachability for all of them. |
mcount = new StateValuesCounters("M",<0,8,20,20>,TRUE)); EndogenousStates(status);
ToScreen | TRUE means output is displayed. |
aM | address to return matrix 0, do not save |
MaxChoiceIndex | FALSE = print choice probability vector (default) TRUE = only print index of choice with max probability. Useful when the full action matrix is very large. |
TrimTerminals | TRUE means states marked as Type terminal are deleted |
TrimZeroChoice | TRUE means states with no choice are deleted |
⋮ CreateSpaces(); meth = new ValueIteration(); DPDebug::outAllV(); meth->Solve();Store everthing to a matrix without printing to the screen:
decl av; ⋮ DPDebug::outAllV(FALSE,&av);If after solving the model you want to save the output table in an external file with labels for the columns use Ox's
savemat()
routine and SVlabels:
⋮ meth->Solve(); savemat("v.dta",av,DPDebug::SVlabels);Print to screen only highest-probability choice index (not all probabilities) for non-terminal states with a real choice:
DPDebug::outAllV(TRUE,FALSE,TRUE,TRUE,TRUE);the screen once model is solved:
aM
is an address.
On the screen the tables are printed out separately for each fixed effect.
ToScreen | TRUE means output is displayed. |
aM | address to return matrix 0, do not save |
MaxChoiceIndex | FALSE = print choice probability vector (default) TRUE = only print index of choice with max probability. Useful when the full action matrix is very large. The columns of the matrix are: StateIndex IsTerminal Aindex EndogenousStates t REIndex FEIndex EV Ρ(α)'and
Column Definition
---------------------------------------------------------------------------------------
StateIndex Integer index of the state in the endogenous state space Θ
IsTerminal The state is terminal, see TermValues
Aindex The index of the feasible action set, A(θ)
EndogenousStates The value of the endogenous state variables at θ
t The time variable, see SetClock and t.
REIndex The index into the random effect state space
FEIndex The index into the fixed effect state space
EV EV(θ) integrating over any exogenous (ε) or
semi-exogenous (η) state variables.
Pinf The stationary distribution if the clock is ergodic
P* The conditional choice probability vector (transposed into a column
and expanded out to match the full potential action matrix.
(or if
|
LOUD
this function is called after each
fixed effect group is complete.
gam | , γ group to reset. |
GorSV | UseCurrent [default] all[bothgroup] already set
Other integer: set all[bothgroup] state vector: set groupoffs using I::OO Not usually called from user code. |
path | Observed path to integrate likelihood over random effects for. |
ToScreen | TRUE, print to output (default) |
aM | = 0 do not save to a matrix (default) address to save too |
MaxChoiceIndex | = FALSE print choice probability vector (default) = TRUE only print index of choice with max probability. Useful when the full action matrix is very large. |
DoAll | go through all reachable states non-negative integer, initial t |
var0 |
non-negative integer, the time period to loop over lohi matrix of first and last index to process |
v
are synched with the internally stored state vector.
dmin | leftmost state variable |
dmax | rightmost state variable |