DistributionsFactories.jl

I’m happy to announce DistributionsFactories.jl, a package that solves a problem most of us have hit: you know the summary statistics you want — a mean and variance, a couple of quantiles, a mode — but you need an actual Distributions.jl object with those properties, and the named families aren’t parameterised that way.

DistributionsFactories.jl inverts that. You give it the family and the moments or quantiles, and it solves for the parameters.

In some cases, all it is doing is using an explicit solution of “moment matching” equations, and in other cases the computation under the hood is more complicated.

e.g.

using DistributionsFactories, Distributions

make_dist(Gamma, mean=5.0, var=3.0)    # Gamma with exactly this mean and variance

make_dist(Normal, q1=10.0, q3=30.0)    # Normal pinned to two quartiles

It also treats feasibility as first-class: dist_exists and available_distributions tell you which families can hit a given target

There are companion Python and R ports, but the Julia package is the master.

Repo: GitHub - Distribution-Matching/DistributionsFactories.jl: A Julia package for probability distributions parametarised by moments (mean, variance, etc.), and other measures (median, constrained domains, etc.). · GitHub

Feedback, bug reports, and requests for additional families are very welcome!

Yoni.

Very useful! :juliaheartpulsing: I wonder if we could omit the distribution family and pick the one with “minimum error” after trying them all. Do you have any comment about that?

That super cool! Since make_dist returns a Distribution, using this inside Turing models “just works”. :partying_face:

using Turing, LinearAlgebra, DistributionsFactories

@model function test123(x)
	b ~ Normal(0, 1)
	σ² ~ make_dist(InverseGamma, mean=1.0, var=3.0)
	y ~ MvNormal(x .* b, σ² * I)
end

x = randn(100)
y = randn(100)

model = test123(x) | (; y)
chn = sample(model, NUTS(), 1000)