1
$\begingroup$

I have the following code with the intention to have a 3D plot:

f0[y_] :=1/(E^((1 + y)^2/2)*Sqrt[2*Pi])
f1[y_] :=1/(E^((-1 + y)^2/2)*Sqrt[2*Pi])

l[y_] :=f1[y]/f0[y]

t[x_] :=NIntegrate[f1[y]^x*f0[y]^(1 - x), {y, -Infinity, Infinity}]

epsilon0[x_] :=-Log[t[x]] + (x*NIntegrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}])/t[x]

epsilon1[x_] :=-Log[t[x]] + ((-1 + x)*NIntegrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}])/t[x]

Plot[epsilon0[x], {x, 0, 1}]
Plot[epsilon1[x], {x, 0, 1}]

I have the following figures

enter image description here! enter image description here!

Good:

However I want to have a single graph probably a 3D plot for epsilon0, epsilon1 and $x$

For example when $x=0.2$ we have $\epsilon_0=0.08$ and $\epsilon_1=1.28$ if I change $x\in[0,1]$ I will get a pair $(\epsilon_0,\epsilon_1)$ for each $x$ and this should be representable in 3D at least as points. But I couldt do it.

Ugly:

What is the 3D figure if we allow any pair of continuous densities $f_0$ and $f_1$ on $\mathbb{R}$ which have $D(f_0,f_1)=2$ and $D(f_1,f_0)=2$ where $D$ is the relative entropy or KL divergence?

$\endgroup$
  • $\begingroup$ Why not ParametricPlot[{epsilon0[x], epsilon1[x]}, {x, 0, 1}] ? $\endgroup$ – b.gates.you.know.what Apr 5 '14 at 19:31
  • $\begingroup$ @b.gatessucks honestly i didnt know it. Right now I plotted and it seems also nice. But the $x$ information is lost. I was thinking $x$ at the $z$ axis and the corresponding $(\epsilon_0,\epsilon_1)$ as a point on the 3d plane. $\endgroup$ – Seyhmus Güngören Apr 5 '14 at 19:40
  • 2
    $\begingroup$ Then you can do ParametricPlot3D[{x, epsilon0[x], epsilon1[x]}, {x, 0, 1}]. I am confused because you picked the tag which answers your question. $\endgroup$ – b.gates.you.know.what Apr 5 '14 at 19:43
  • $\begingroup$ @b.gatessucks ahahaha thats true! $\endgroup$ – Seyhmus Güngören Apr 5 '14 at 19:45
  • $\begingroup$ Do we really need a parametricplot3d tag? As it seems it was created here. $\endgroup$ – Silvia Apr 6 '14 at 5:27
1
$\begingroup$

Detail : your functions are simple enough that the integrals can actually be evaluated analytically.

t2[x_] = Integrate[f1[y]^x*f0[y]^(1 - x), {y, -Infinity, Infinity}]
(* E^(2 (-1 + x) x) *)

epsilon02[x_] = -Log[t2[x]] + 
    (x*Integrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}]) / t2[x]
(* 2 x (-1 + 2 x) - Log[E^(2 (-1 + x) x)] *)

epsilon12[x_] = -Log[t2[x]] + 
  ((-1 + x) * Integrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}]) / t2[x]
(* 2 (-1 + x) (-1 + 2 x) - Log[E^(2 (-1 + x) x)] *)

Simplify[epsilon02[x], Assumptions -> {0 <= x <= 1}]
(* 2 x^2 *)

Simplify[epsilon12[x], Assumptions -> {0 <= x <= 1}]
(* 2 (-1 + x)^2 *)

ParametricPlot3D[{epsilon02[x], epsilon12[x], x}, {x, 0, 1}]

plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.