Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to create some density functions based on some distance measure $D$. As a base density function lets say I have a Gaussian density $f$ with mean $-1$ and variance $1$. I would like to create some smooth and nice density functions $g$ randomly which are at least $\epsilon$ close to my base density $f$. The set of all possible densities can be written down as

$${\cal{F}}=\{g_0: D(g,f)\leq \epsilon\}$$


$$D(g,f)=\int_{-\infty}^\infty g(y)\log \left(\frac{g(y)}{f(y)}\right)\mathrm{d}y$$

and since $g$ are densities, we also have additionally

$$\int_{-\infty}^\infty g(y)\mathrm{d}y=1,\quad g(y)>0 \quad\forall y$$

How can I create such $g$ functions in Mathematica? is there a simple way?

Thank you very much for reading this post and thanks in advance for any help.

share|improve this question
You could pick an arbitrary "smooth and nice" random function $h:\mathbb R\to\mathbb R$ and let $g(y) := f(y)\exp(\alpha h(y)+\beta)$. Then by choosing $\alpha$ sufficiently small and $\beta$ to satisfy $\int g(y)\,\mathrm dy=1$, you can get your desired properties. So the problem reduces to creating an arbitrary real-valued "smooth and nice" function. You are sampling from an infinite-dimensional function space, so you will probably have to narrow it down somehow. –  Rahul Narain Oct 30 '13 at 5:01
(Note that the expression for $D(f,g)$ becomes very simple with this approach. Unfortunately $D$ is not symmetric in $f$ and $g$, but if they are "close together" the difference should be small.) –  Rahul Narain Oct 30 '13 at 5:04
@Rahul Narain :) thanks for the suggestion. –  Seyhmus Güngören Oct 30 '13 at 7:58
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.