mathnet-numerics icon indicating copy to clipboard operation
mathnet-numerics copied to clipboard

Lack of useful generic common ground when working with both discrete and continuous probability distributions

Open charging815 opened this issue 4 months ago • 2 comments

I've been working with MathNet.Numerics.Distributions recently and I'm really confused by certain design decisions. When writing generic algorithms that operate on probability distributions; it's really difficult to handle both discrete and continuous cases cleanly. The lack of a common interface for querying likelihood (and some other stuff) forces silly hacks and boilerplate code. Both IDiscreteDistribution and IContinuousDistribution share a lot of methods that do the same things, so why they weren't just in IUnivariateDistribution (for querying likelihood, IDiscreteDistribution uses .Probability(int) while IContinuousDistribution uses .Density(double), what's that about?). I'm considering just forking this project and moving those shared functions to IUnivariateDistribution. Haven't properly checked out multivariate distributions yet, but they could maybe benefit from some changes too. Not sure what you guys plan for it, just dropping my experience here.

charging815 avatar Aug 21 '25 14:08 charging815

That’s not really my area of expertise, but you could send a PR if you’d like

jkalias avatar Aug 21 '25 17:08 jkalias

I explored deeply into what it'd take to create a common interface for continuous and discrete distributions, while also looking into what change would be required for multivariate distributions. It can definitely be done, but it may bring some breaking changes. A lot of heavy lifting will be done by generics, and relying on class variables for multivariate distributions (which continuous and discrete distributions already do since their interface methods can be limiting, so I think that'd be a fair trade off). If you're interested in that, I could show some examples.

charging815 avatar Aug 31 '25 12:08 charging815