Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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 Oct 30 '13 at 5:04
@Rahul Narain :) thanks for the suggestion. – Seyhmus Güngören Oct 30 '13 at 7:58

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.