Closed jmrichardson closed 2 years ago
Can you try it making a deep copy of s? Python is pass by reference to object, and the state is a mutable dictionary.
import copy s1 = copy.deepcopy(s) x_new, x_std_new, s_new = thinking_slow_and_fast(y=yi, s=s, k=3) x_prime, x_std_prime, s_newish = thinking_slow_and_fast(y=yi, s=s1, k=3)
Yes, it does work. I also noticed that you must do a deep copy prior to each. This code snippet works:
for i in range(0, 10):
s1 = copy.deepcopy(s)
x_prime, x_std_prime, s_newish = thinking_slow_and_fast(y=yi, s=s1, k=3)
print(x_prime)
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.17208556479699, 75.16299642564626, 75.15390728649554]
This does not:
s1 = copy.deepcopy(s)
for i in range(0, 10):
x_prime, x_std_prime, s_newish = thinking_slow_and_fast(y=yi, s=s1, k=3)
print(x_prime)
[75.17208556479699, 75.16299642564626, 75.15390728649554]
[75.30241054501099, 75.29423761273385, 75.28606468045672]
[75.41158896477022, 75.4043743792711, 75.39715979377199]
[75.5032450322357, 75.49692063825306, 75.49059624427044]
[75.58093886351598, 75.5753962430606, 75.56985362260521]
[75.6477567127686, 75.64288262630443, 75.63800853984024]
[75.70620517294356, 75.70189703172484, 75.69758889050611]
[75.75824066561717, 75.7544115365491, 75.75058240748105]
[75.80534998939467, 75.80192861818831, 75.79850724698197]
[75.84864166294314, 75.84557048199703, 75.84249930105092
Excellent, so it appears that I can save the state of the model by doing a deep copy. Thanks for the help!
That's right, because the second way you are actually modifying s each time. Gotta love Python.
There should be a comment in the docs about this. Let's leave it open until then.
Awesome, loving this package! Will try to implement my use case and let you know how it goes on slack. Thanks again!
Hi, I am not sure why predictions are not consistent. I ran the following:
Then, wanted to verify predictions using state variable "s" and the same y using the following simple loop code:
I was expecting to see the same predictions for each loop given that I am using the same yi and s variables (ie they haven't changed). But got different predictions:
Shouldn't using the same state "s" and the same "y" give us the same prediction?