- #1
Hejdun
- 25
- 0
Consider the functions
[tex] g(x)=e^x/(1+e^x)^2 [/tex]
and
[tex]f(x) = vf_1(x) + (1-v)f_2(x) [/tex].
where
[tex] f_1(x)=\dfrac{1}{\sqrt{2\pi\sigma^2_1}}e^{-\dfrac{x^2}{2\sigma^2_1}},\,\,\, f_2(x)=\dfrac{1}{\sqrt{2\pi\sigma^2_2}}e^{-\dfrac{x^2}{2\sigma^2_2}}[/tex]
and
[tex] -\infty < x < \infty, \,\,\, 0 < v < 1, \,\,\, \sigma^2_1 > 0, \,\,\, \sigma^2_2 > 0. [/tex]
What I want to do basically is to approximate the function g(x) with f(x) by selecting proper values of [tex] v, \sigma^2_1, \sigma^2_2. [/tex] Just by inspection and manual iteration I concluded that something like [tex] v=0.3, \sigma^2_1=6.2, \sigma^2_2=1.95 [/tex] provides a fairly good approximation, but of course, I want to carry out the analysis more formally.
First I considered minimizing
[tex] \int_{-\infty}^{\infty} ( g(x) - (vf_1(x) + (1-v)f_2(x)) )^2 dx. [/tex]
The problems is that this integral will not yield an analytical result.
Second, what could also be of interest is to minimize abs(g(x)-f(x)) for all x so that we will at least know the maximum error that could occur.
My question is therefore twofold:
1) Do you have any suggestions about solving this problem analytically?
2) If resorting to numerical optimization when minimizing the integral above, how do I implement it in Mathematica? I tried the following code but it failed.
fz1 := (1/Sqrt[2*Pi*vz1])*Exp[-z^2/(2*vz1)]
fz2 := (1/Sqrt[2*Pi*vz2])*Exp[-z^2/(2*vz2)]
gz := Exp[z]/(1 + Exp[z])^2
uz := gz - (v*fz1 + (1 - v)*fz2)
Uz[vz1_?NumericQ, vz2_?NumericQ, v_?NumericQ] :=
NIntegrate[uz^2, {z, -Infinity, Infinity}]
NMinimize[{Uz, vz1 > 0 && vz2 > 0 && v > 0 && v < 1}, {vz1, vz2, v}]
All suggestions are most welcome!
[tex] g(x)=e^x/(1+e^x)^2 [/tex]
and
[tex]f(x) = vf_1(x) + (1-v)f_2(x) [/tex].
where
[tex] f_1(x)=\dfrac{1}{\sqrt{2\pi\sigma^2_1}}e^{-\dfrac{x^2}{2\sigma^2_1}},\,\,\, f_2(x)=\dfrac{1}{\sqrt{2\pi\sigma^2_2}}e^{-\dfrac{x^2}{2\sigma^2_2}}[/tex]
and
[tex] -\infty < x < \infty, \,\,\, 0 < v < 1, \,\,\, \sigma^2_1 > 0, \,\,\, \sigma^2_2 > 0. [/tex]
What I want to do basically is to approximate the function g(x) with f(x) by selecting proper values of [tex] v, \sigma^2_1, \sigma^2_2. [/tex] Just by inspection and manual iteration I concluded that something like [tex] v=0.3, \sigma^2_1=6.2, \sigma^2_2=1.95 [/tex] provides a fairly good approximation, but of course, I want to carry out the analysis more formally.
First I considered minimizing
[tex] \int_{-\infty}^{\infty} ( g(x) - (vf_1(x) + (1-v)f_2(x)) )^2 dx. [/tex]
The problems is that this integral will not yield an analytical result.
Second, what could also be of interest is to minimize abs(g(x)-f(x)) for all x so that we will at least know the maximum error that could occur.
My question is therefore twofold:
1) Do you have any suggestions about solving this problem analytically?
2) If resorting to numerical optimization when minimizing the integral above, how do I implement it in Mathematica? I tried the following code but it failed.
fz1 := (1/Sqrt[2*Pi*vz1])*Exp[-z^2/(2*vz1)]
fz2 := (1/Sqrt[2*Pi*vz2])*Exp[-z^2/(2*vz2)]
gz := Exp[z]/(1 + Exp[z])^2
uz := gz - (v*fz1 + (1 - v)*fz2)
Uz[vz1_?NumericQ, vz2_?NumericQ, v_?NumericQ] :=
NIntegrate[uz^2, {z, -Infinity, Infinity}]
NMinimize[{Uz, vz1 > 0 && vz2 > 0 && v > 0 && v < 1}, {vz1, vz2, v}]
All suggestions are most welcome!