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

Add random seed to wealth dynamics lecture #50

Open
jstac opened this issue Dec 8, 2019 · 10 comments
Open

Add random seed to wealth dynamics lecture #50

jstac opened this issue Dec 8, 2019 · 10 comments

Comments

@jstac
Copy link
Contributor

jstac commented Dec 8, 2019

For example, we want the figure showing Gini coefficient vs mu_r in weath_dynamics.rst to be unchanging.

This is quite subtle due to use of Numba and parallelization (which tends to cause problems with seeds). I'm not sure it can be done but it needs to be investigated and a rewrite of the code might be required.

@shlff shlff transferred this issue from QuantEcon/lecture-source-py Mar 26, 2020
@Harveyt47
Copy link
Member

I've been in search of a way to set a seed once for the whole lecture and I noticed this.

image

It seems like the seed does not stay across cells.

@mmcky
Copy link
Contributor

mmcky commented Apr 24, 2020

@Harveyt47 I think what is happening here is that RandomState is setting a deterministic sequence of values. So randn is extracting numbers from that sequence right?

@Harveyt47
Copy link
Member

That's what I thought but when I run the first cell it always returns 0.471... Is that consistent with what your saying @mmcky. I would have expected it to change.

@Harveyt47
Copy link
Member

Harveyt47 commented Apr 24, 2020

Also using this type of method has issues with jitted classes and functions. I'm not sure jit can interpret the seed variable in the above pic.

I've noticed that in the draw function in the qe library we can not set a seed for it.

@mmcky
Copy link
Contributor

mmcky commented Apr 24, 2020

when you rerun the first cell you're just reseting the sequence again right?

@Harveyt47
Copy link
Member

Harveyt47 commented Apr 24, 2020

I see. Thanks @mmcky

@jstac
Copy link
Contributor Author

jstac commented Apr 24, 2020

@Harveyt47 , I recommend you create a little test notebook where you try to understand random seeds and how they interact with numba and prange.

You might need to do some background reading in the numba docs. Once you have the main ideas worked out, it would be great if you could share it with us. We might even end up writing a short lecture on this topic, because not many people understand it, including me :-)

@Harveyt47
Copy link
Member

Hi @jstac that sounds like a great idea. I'll get on it

@jstac
Copy link
Contributor Author

jstac commented Jun 21, 2020

@Harveyt47, would you mind to let us know the status of this?

@Harveyt47
Copy link
Member

Hi @jstac from the research I did the main problem is setting a seed across all the threads.

For example in the case of the gini coefficient curve the household wealth distribution comes from the function update_cross_section. If we were to simply set a seed in that function it would only get stored a TLS slot in the main thread, while the other threads just get random junk based on the entropy value picked up and stuffed into their TLS slot on launch. So the first batch (25000) of households will have the same seed everytime but the other batches will have different seeds and change everytime. This causes the household wealth distribution to change everytime, hence causing the gini coefficient to change.

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

No branches or pull requests

3 participants