alecheckert / saspt

State arrays for single particle tracking
MIT License
9 stars 6 forks source link

Posterior Probability does not add up to 1 #10

Closed antanij closed 7 months ago

antanij commented 7 months ago

Hi Alec, here is another one, more of a clarification/question than an issue.

I noticed that the sum of posterior probabilities over all values of diffusion coefficients is 0.0278 and not 1. Interestingly, the sum is same for two different grids of D. Could you please explain why? Or am I missing something?

Given that this is correct, should the immobile fraction (e.g., Fig. 5C in your eLife paper about this code) be defined as

sum(P(D<threshold)) / sum(P(all))

instead of just the numerator?

alecheckert commented 7 months ago

Usually we'll output the parameter to the posterior (Dirichlet) distribution over states, rather than a probability distribution. The posterior mean probability distribution over states is just the normalized Dirichlet parameter (divide each value in the Dirichlet parameter by the sum over all parameters).

But just to make sure I'm thinking about the right thing here, could you share a code snippet where you're getting 0.0278? Thanks in advance.

antanij commented 7 months ago

See below the snippet you asked for. Is P the Dirichlet parameter you referred to?

D, loc_errors = SA.parameter_values P = np.mean(SA.posterior_occs,axis=1)

I plot D versus P, which seems to be similar to the data plotted in Fig 5A (bottom panels) of your paper as well as figs 2c & 2e of Chen et al., eLife, 2022. Correct?

Or should I do:

P = np.mean(SA.posterior_occs,axis=1)/np.sum(SA.posterior_occs,axis=1)

alecheckert commented 7 months ago

Ah okay - you'll need to sum over the second axis, rather than taking the mean.

Just to make sure:

occs = SA.posterior_occs

# Should be 1
print(occs.sum())

# Should be (len(diff_coefs), len(loc_errors))
print(occs.shape)

# Marginal occupations over diffusion coefficient
occs = occs.sum(axis=1)

# Should still be 1
print(occs.sum())
antanij commented 7 months ago

Perfect, thank you so much!