Find number of parameters in a distribution

Suppose I’m looping over a large vector of distributions from Distributions.jl.

How can I automatically find how many parameters there are in a distribution?
I want a function nparams(d) where:
nparams(Normal)=2 since Normal(μ,σ)
nparams(BetaBinomial)=3 since BetaBinomial(n,α,β)

1 Like

nparams(d) = length(fieldnames(typeof(d)))
maybe

1 Like

Thank you @jling!

length(fieldnames(Exponential))  #1 correct
length(fieldnames(typeof(Exponential)))    #2 incorrect

nparams(d) = length(fieldnames(d)) #SOLUTION

sorry, thought your d is an instance of a distribution.

1 Like