johannesulf / nautilus

Neural Network-Boosted Importance Nested Sampling for Bayesian Statistics
https://nautilus-sampler.readthedocs.io
MIT License
73 stars 8 forks source link

How to sample an image #54

Closed RITCHIE1497 closed 1 month ago

RITCHIE1497 commented 1 month ago

Hello all,

I have an array of shape (n,m) and a chi_squared function for likelihood. The chi_squared function takes the image as parameter. I would like to sample the image such that each iteration changes randomly all the pixels given a prior. The examples on the documentation only takes a few parameters, like 2 or 3. How to sample (n,m) pixels? How can I sample without prior? And how to sample with using a prior?

Cheers, Ricardo

johannesulf commented 1 month ago

Hi Ricardo, thanks for reaching out. I hope I understand the issue correctly. It seems like you have a likelihood that takes an array of shape (n, m) as an input and you'd like to sample this array of shape (n, m).

In principle, you could simply flatten the two-dimensional array of shape (n, m) into a one-dimensional array of length n x m. That said, I'm worried that the number of parameters (n x m) may be too large. For various reasons, nautilus is not designed to deal with more than around 50 parameters. If m x n is much larger than that, I would suggest you look into other sampling methods such as slice sampling or Hamiltonian Monte Carlo.

Finally, can you maybe clarify what you mean by sampling "without prior"?

RITCHIE1497 commented 1 month ago

Hello johannesulf, thank you very much for your response. Regarding the size, the images are usually large, ranging from 512x512 to 8196x8196, and there are several images. So I will probably need to implement the methods you mentioned. By any chance, do you know if those methods are available in a Python library? I will only use the log likelihood sampler. Thank you in advance. Ricardo.

johannesulf commented 1 month ago

Hi Ricardo, yes, the sizes you mentioned are way too large for many samplers, including nautilus. You could give dynesty a try. For this many dimensions, it would automatically switch to slice sampling. But I'm not very optimistic that this would work, either.

Sampling with millions of parameters is a very challenging problem. This is not an area I'm very familiar with. Hamiltonian Monte Carlo seems to be what most people use in this case. Unfortunately, I can't point to any specific Python package in that case.