pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Add `rng_fn` to CAR/ICAR

Open jessegrabowski opened this issue 9 months ago • 14 comments

Description

I was talking to @theorashid who linked me to this case study of CAR priors. It seems like they're just MvNormals, but with degenerate covariance matrices. We can now sample from such distributions use the new method="eig" or method="svd" argument. So a potential rng_fn would just make an appropriate MvNormal with the method argument set, then return it's rng_fn.

Looking at the logp method for these distributions, it seems like it's just using the eig method; so we might be able to simplify these to wrappers around MvNormalRV that just constructs the mean/covariance and sets the appropriate method, but that's a step beyond what this PR is asking for.

jessegrabowski avatar Mar 09 '25 09:03 jessegrabowski

Plus some special logic for sparse covariances that would be nice to support in MvNormal as well?

ricardoV94 avatar Mar 09 '25 09:03 ricardoV94

A hidden internal SparseMvNormal, in the vein of PrecisionMvNormal would be nice. We could rewrite to it when we see the covariance is sparse.

One issue I foresee is that we don't have sparse implementations of relevant algorithms (Cholesky, Eig, SVD, and Solve). I know sparse cholesky exists, because @bwengals was telling me it's a nice one for GP stuff. For the others I have no idea.

But also beyond the scope of this issue

jessegrabowski avatar Mar 09 '25 09:03 jessegrabowski

Hi @jessegrabowski ! Hope you are fine ! If no one is working on this issue , could you assign this to me I'd like to solve this. Thank You !

Muhammad-Rebaal avatar Mar 11 '25 06:03 Muhammad-Rebaal

We don't assign issues, you can just open a PR

ricardoV94 avatar Mar 11 '25 06:03 ricardoV94

We don't assign issues, you can just open a PR

Ok sure thing I'll open a draft one.

Muhammad-Rebaal avatar Mar 11 '25 07:03 Muhammad-Rebaal

Hi @jessegrabowski , @ricardoV94 , I started this PR ( #7879 ) to address this issue. Please note I've only implemented ICARRV ( and corresponding test ) for now. I was hoping to get your reviews and then the implementation for CARRV would be easier. Please let me know your thoughts. Thank you 🙏

asifzubair avatar Jul 30 '25 02:07 asifzubair

Just because we can, should we? Are these draws valid in any meaningful sense? Are they useful?

ricardoV94 avatar Aug 11 '25 13:08 ricardoV94

It would enable prior predictive checks for ICAR models, which would be nice.

jessegrabowski avatar Aug 11 '25 13:08 jessegrabowski

But are they valid/meaningful? This is an improper prior IIUC

ricardoV94 avatar Aug 11 '25 13:08 ricardoV94

Is it something like that? https://stats.stackexchange.com/a/159322

And if valid, should we use svd specifically, instead of eigh?

ricardoV94 avatar Aug 11 '25 13:08 ricardoV94

Yeah I might have missed some details.

To merge the PR, I would want to see that the prior and the no-data MCMC gives the same answer

Is it something like that? https://stats.stackexchange.com/a/159322

Yes, that was my understanding when I wrote the issue

jessegrabowski avatar Aug 11 '25 13:08 jessegrabowski

I'm even more skeptical you can use mcmc for any source of truth: https://stats.stackexchange.com/questions/211917/sampling-from-an-improper-distribution-using-mcmc-and-otherwise

MCMC wmith improper flat will not give you a flat distribution, it can't without infinite bits of precision (and infinite runtime I guess)

ricardoV94 avatar Aug 11 '25 13:08 ricardoV94

Yes, that was my understanding when I wrote the issue

Also would need to check that calling numpy with those other methods achieves that goal. Implementation/explanation seems to suggest padding with zeros specifically, I didn't bother to read the formula to see if ignoring this detail would change anything.

ricardoV94 avatar Aug 11 '25 13:08 ricardoV94

hello sir @jessegrabowski i want to solve this problem can you please tell me that ICAR or proper CAR ,which is implementing here

premshaw04 avatar Nov 02 '25 12:11 premshaw04