-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
track_vars cannot track PrefShkNow #808
Comments
Try removing the call to makeShockHistory().
…On Thu, Aug 20, 2020 at 9:48 AM Sebastian Benthall ***@***.***> wrote:
*Describe the bug*
Adding PrefShkNow to track_vars results in broken history records.
*To Reproduce*
Run this code:
https://gist.github.com/sbenthall/e398fd3c389a9cc094974c397e49b160
See this output:
python pref_test.py
0.6904681186891202 0.69046812
/home/sb/projects/econ-ark/HARK/HARK/interpolation.py:1721: RuntimeWarning: All-NaN slice encountered
y = self.compare(fx,axis=1)
[[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
...
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]]
[[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
...
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]
[nan nan nan ... nan nan nan]]
*Expected behavior*
When PrefShkNow is removed from track_vars, and the corresponding print
statement is removed, the numerical values of cNrmNow are displayed.
$ python pref_test.py
0.6904681186891202 0.69046812
[[1.31820519 1.13599726 1.19117047 ... 1.15580804 0.92238984 0.79139412]
[1.75227515 0.87249487 1.03166147 ... 1.09467154 1.04217198 0.81947656]
[1.6132044 1.21100077 1.10807752 ... 1.04517571 0.97166597 0.93927158]
...
[1.41013941 0.98367178 0.99266247 ... 1.19269696 1.00552796 1.02108079]
[1.19004436 1.32309231 1.52353897 ... 1.10650642 0.87607768 0.92796219]
[1.07060879 0.94171512 1.06713576 ... 0.94867343 0.8665761 0.93075895]]
I expect a similar thing when adding PrefShkNow to be tracked.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#808>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFMUWABBCZUFHXX7OPLSBUSRFANCNFSM4QGCIQ4A>
.
|
That worked.... Let's figure out how to make this documented/obvious and fail more gracefully. |
Interesting. So, this is specifically a problem with how adding it to track_vars interacts with makeShockHistory |
Hmm. So, one thing I'm noticing is that a matrix full of https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L481 Another is that makeShockHistory calls initializeSim(), but in the test code is called before initializeSim(). initializeSim() clears the history: which I think would erase everything already done by makeShockHistory. But if I do NOT call initializeSim() after makeShockHistory(), I get this error:
Which is dealing with the special case in getMortality which expects https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L515-L516 |
initializeSim() needs to be called after makeShockHistory() because t_sim
has iterated up to T_sim, so it's trying to draw row 10 of
self.history['who_dies'], which only goes up to row 9.
…On Thu, Aug 20, 2020 at 7:43 PM Sebastian Benthall ***@***.***> wrote:
Hmm. So, one thing I'm noticing is that a matrix full of nans is what you
initialize each shock variable with at the beginning of makeShockHistory
https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L481
Another is that makeShockHistory calls initializeSim(), but in the test
code is called *before* initializeSim().
initializeSim() clears the history:
https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L423
which I think would erase everything already done by makeShockHistory.
But if I do NOT call initializeSim() after makeShockHistory(), I get this
error:
Traceback (most recent call last):
File "pref_test.py", line 20, in <module>
agent.makeShockHistory() # This is optional
File "/home/sb/projects/econ-ark/HARK/HARK/core.py", line 687, in simulate
self.simOnePeriod()
File "/home/sb/projects/econ-ark/HARK/HARK/core.py", line 445, in simOnePeriod
self.getMortality() # Replace some agents with "newborns"
File "/home/sb/projects/econ-ark/HARK/HARK/core.py", line 520, in getMortality
who_dies = self.history['who_dies'][self.t_sim,:]
IndexError: index 10 is out of bounds for axis 0 with size 10
Which is dealing with the special case in getMortality which expects self.read_shocks
== True
https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L515-L516
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#808 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFOUEO444QNVTCFJZFTSBWYKDANCNFSM4QGCIQ4A>
.
|
Hmmm. Ok, so let be get this straight...
It's necessary then to call initializeSim again:
What does clearHistory() do? https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L685-L698 It erases the history of all the track_vars. This explains the bug! |
So the question now is how to fix it. From where I'm sitting, the use case fo What makes A simple fix would be to have makeShockHistory use a different dictionary for storage, |
That's fine. But I thought you said nothing breaks as long as you don't
put `PrefShkNow` in track_vars *and* call makeShockHistory?
…On Fri, Aug 21, 2020 at 8:15 AM Sebastian Benthall ***@***.***> wrote:
So the question now is how to fix it.
From where I'm sitting, the use case fo track_vars is very different from
the use case of makeShockHistory(). They should not be using the same
data structure (this history dictionary, which used to be *_hist object
attributes) for their data.
What makes makeShockHistory possible is precisely that the shocks are
exogenous, and so can be precomputed. This relates to what is being
discussed in #798 <#798>. They can
be precomputed because there are not dependent on endogenous variables;
with respect to the partial ordering of computation, they are always at the
root.
A simple fix would be to have makeShockHistory use a different dictionary
for storage, shock_hist.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#808 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFM3GAAHP2KTRFHPQL3SBZQO5ANCNFSM4QGCIQ4A>
.
|
Yes, that's correct.
or...
|
The first one, with a triple nested loop as well.
…On Fri, Aug 21, 2020 at 9:29 AM Sebastian Benthall ***@***.***> wrote:
Yes, that's correct.
But would you rather tell the user:
- If you want to track the history of a variable, then add it to
'track_vars', *unless* it's a shock variable and you're calling
makeShockHistory, in which case, don't worry, the shock history is
maintained for you...
or...
- If you want to track the history of a variable, add it to track_vars
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#808 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFM6DUHREHH6PABTWKTSBZZCBANCNFSM4QGCIQ4A>
.
|
Describe the bug
Adding
PrefShkNow
totrack_vars
results in broken history records.To Reproduce
Run this code:
https://gist.github.com/sbenthall/e398fd3c389a9cc094974c397e49b160
See this output:
Expected behavior
When
PrefShkNow
is removed fromtrack_vars
, and the corresponding print statement is removed, the numerical values ofcNrmNow
are displayed.I expect a similar thing when adding
PrefShkNow
to be tracked.The text was updated successfully, but these errors were encountered: