Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay discretization of random parameters #640

Closed
sbenthall opened this issue Apr 21, 2020 · 4 comments
Closed

delay discretization of random parameters #640

sbenthall opened this issue Apr 21, 2020 · 4 comments

Comments

@sbenthall
Copy link
Contributor

In conversation, @llorracc floated the idea that HARK, like Mathematica, could delay the discretization of random variables until it was necessary for sampling.

This seems doable with changes to the distribution representation. See #519 #611

Based on the existing code, the main design question that raises is when the number of values in the discretized distribution is set. Currently, this is a parameter given to the model on initialization:

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsPrefShockModel.py#L24

@llorracc
Copy link
Collaborator

I feel that the object that contains the discretized results needs to store all the parameters that went into its creation. One reason for this is that users often change parameter values without realizing that in order for those parameter values to actually apply they need to rediscretize (and also re-solve) the model. If the parameters were stored, we could do a quick check of whether the current values match the ones that were in force at the time of discretization, and if not we could at least give a warning. (We would NOT want to prohibit the use of a different discretization than the parameters currently specify, because that is something that occasionally someone might want to do deliberately).

@sbenthall
Copy link
Contributor Author

sbenthall commented Feb 11, 2021

Looking over the source code on this, it looks to me that there are two different code patterns used around instantiating random variables.

(1) In some cases, the random variable object is constructed, left continuous, and immediately sampled. This happens in simBirth

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py#L1510-L1514

In this case there is no discretization, so this ticket does not apply.

(2) In other cases, a distribution is approximated and stored. This is done partly because the distribution is a joint distribution (though in this particular cases it is an independent join distribution):

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py#L2529-L2548

Here's another case:
https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsPrefShockModel.py#L128-L133

These are being called when the model is initialized.

These shocks are used in the model code in two ways:

(3) In simulation, they are drawn from when shocks are sampled:

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py#L1990

One question is: Should the distributions be discretized before being sampled for simulation shocks? The current code is inconsistent: using continuous draws for the birth of agents (see (1)) and discrete draws for simulations.

(4) These distributions are also used in the solution code; they are discretized before the calcExpectations operation:

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py#L752-L766


So reviewing this issue carefully, it is quite connected to issues #660 and #914

The main question for me is: When do we want to be using the continuous variable, and when do we want to be using the discretized version?

See also #120.

@sbenthall
Copy link
Contributor Author

Today @llorracc says that the only reason to delay discretization is ... to assist in debugging of the non-discretized model.

@sbenthall
Copy link
Contributor Author

Because there's no major motivation for delaying discretization of a random variable, I'll close this ticket.

I'll bring up the question of simulation in the continuous space in issue #660

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants