# Need to sample from two-parameter univariate exponential distribution

Hello,

I need to sample from a two-parameter family of continuous univariate distributions supported on the interval [0,C] where C is around 10^{12}. The parameters are \alpha and \beta and the PDF is proportional to e^{-\alpha x - \beta x^2}, so this is a two-parameter exponential family.

What’s the easiest way to do this? Do I have to write my own distribution, or is there some support in Julia for exponential families?

In my use case, \alpha and \beta are obeying a differential equation, so I sample from different distributions as time changes, hence I need to sample from the entire family.

Can’t you complete the square? e^{-\alpha x - \beta x^2} = \mathrm{constant} \times e^{-\beta (x + \alpha/2\beta)^2}, so it’s equivalent to drawing from a Gaussian distribution with a shifted mean.

4 Likes

Wow that’s a lovely solution! Yes I will have to truncate my Gaussian both sides, but should work!

Note that Distributions.jl supports truncated normal distributions.

1 Like