EigenRand icon indicating copy to clipboard operation
EigenRand copied to clipboard

Adding PDFs/CDFs to the main library

Open ManifoldFR opened this issue 1 year ago • 5 comments

Hi @bab2min ! Thanks for the great work you've done on this library. I'm using it for a purpose (importance sampling) where I need to compute the probability density or cumulative distribution functions of what I'm sampling.

I noticed some benchmarks implement some 1D pdfs and cdfs. Would you be interested in having those be part of the main library, as well as multivariate densities e.g. the multivariate normal density? For now what I've implemented is in my own client library, but I could make a PR if there's interest.

ManifoldFR avatar Jul 17 '23 10:07 ManifoldFR

Hi @ManifoldFR Thank you for your suggestion. PR is always welcome. It will be great if pdfs and cdfs were included in the library, especially separated header file.

bab2min avatar Jul 17 '23 12:07 bab2min

Great! You'd prefer a separate header file where they are implemented as free functions? Not member functions of the XXGen (e.g. MvNormalGen) classes?
If you prefer the former I'll do that.

ManifoldFR avatar Jul 17 '23 15:07 ManifoldFR

@ManifoldFR I thougt a free function would be good at first, but implementing as member functions looks better. Is it correct that you are intending something like the following?

auto norm = NormalGen{0, 1};
norm.pdf(x) == exp(-x*x/2)/sqrt(2*pi)

bab2min avatar Jul 17 '23 16:07 bab2min

@ManifoldFR I thougt a free function would be good at first, but implementing as member functions looks better. Is it correct that you are intending something like the following?

auto norm = NormalGen{0, 1};
norm.pdf(x) == exp(-x*x/2)/sqrt(2*pi)

Yes, that's what I'm thinking of. We'd be replicating the API of scipy.stats: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.multivariate_normal.html

It's also useful because in some classes such as MvNormalGen we already have a lower-triangular square root of the covariance matrix stored, and can use it to compute the determinant in the PDF

ManifoldFR avatar Jul 17 '23 16:07 ManifoldFR

@ManifoldFR Great! I cancel my words "separated header file". Please feel free to add member functions :)

bab2min avatar Jul 17 '23 16:07 bab2min