dingo-gw / dingo

Dingo: Deep inference for gravitational-wave observations
MIT License
55 stars 18 forks source link

Sampling Importance Resampling (SIR) #135

Closed nihargupte-ph closed 1 year ago

nihargupte-ph commented 1 year ago

During one of the LIGO PE calls someone mentioned PE codes requiring samples that don't have weights attached to them. I don't think this was a requirement for the review though. Recently I had to implement this for plotting purposes. Should be able to put this into dingo as most of the work is already done with the importance sampling. Effectively, we would only need to add a function to dingo.core.result which takes the importance sampled result (or a result with weights in it) and resamples with replacement from that distribution. The probability of drawing each sample is proportional to it's importance weight. In pseudocode:

df = {dataframe with weights and samples}
df.sample(n=n_samples, weights=df["weights"], replace=True)
stephengreen commented 1 year ago

Right, this is something that we need to implement, and I think it needs to be sampling with replacement as you indicated (otherwise the number of samples returned is too low). It makes sense to be in the Result class, and probably we need to also be able to toggle this with dingo-pipe.

nihargupte-ph commented 1 year ago

Looks like it is working:

image