nwlandry / complex-network-reconstruction

2 stars 0 forks source link

Proposed fix for inference code #5

Closed jg-you closed 12 months ago

jg-you commented 1 year ago

https://github.com/nwlandry/modeling-and-inferring-complex-contagion/blob/a2c190997eb00702d3075a27f7f38685208c4158/src/inference.py#L160C1-L164C1

Not sure this is correct.

Shoud be $\sum\ell \log B(m\ell + a\ell, n\ell + b_\ell)$

where $a_\ell,b_ell$ are hyperparametrs. We can set them to 1 for simplicity.

Then you'd have (where al, bl are N-1 length vectors, and same for nl and ml)

def dynamics_log_posterior(nl, ml, al, bl):
   return sum(betaln(ml + al, nl + bl))

This is using the fact that betaln evaluates to an array of values of N values of the Beta function when given two arrays of length N

jg-you commented 1 year ago

Basically I'm not sure about summing over axis=1 in the other version, but I might not be following your code. It looks like nl is already of length N, should not be summed.

nwlandry commented 12 months ago

I double-checked this, and the nl/ml matrices are $N \times N$ matrices where the rows are node index, and the columns are the $\ell$ value. The function sums over axis 0 to get total counts. I believe that it's correct, and I will add some unit tests when I get a chance.