lnccbrown / HSSM

Development of HSSM package
Other
72 stars 10 forks source link

Reconciliate re-sampling behavior #481

Open digicosmos86 opened 1 week ago

digicosmos86 commented 1 week ago

Describe the bug

Currently, HSSM keeps a reference to the result of the last sampling. In #476, a bug was found that this internal InferenceData object does not get updated when InferenceData object already exists. This issue clarifies HSSM's behavior once the users resample:

Expected behavior

  1. HSSM still keeps reference to the result of the last call to model.sample(). All results of the previous samples will be overwritten.
  2. However, if there is an existing reference to a previous result, that reference will still be pointed to the result when the reference is created:
trace1 = model.sample(...) #sample1
model.sample(...) #sample2

We expect that trace1 will still point to the first sample. Implicitly, if the user does not assign the result of the call to model.sample(), then the result of the previous call will be overwritten, and the InferenceData will be garbage collected.

If there is a new reference to the second model.sample() call, then we expect the samples to be different.

trace1 = model.sample(...)
trace2 = model.sample(...)

trace1 is trace2 #False
  1. Any changes to the InferenceData object will directly change the object directly attached to the model (default Python behavior)
trace1 = model.sample(...)
trace2 = model.traces

trace1 is trace2 #True

del trace2["posterior_predictive"]

Then trace1 should not no longer have posterior_predictive group.