       Re: using FindMinimum to minimize a function involving NIntegrate

• To: mathgroup at smc.vnet.net
• Subject: [mg15577] Re: [mg15483] using FindMinimum to minimize a function involving NIntegrate
• From: jtischer at col2.telecom.com.co (Cl-Jurgen Tischer)
• Date: Tue, 26 Jan 1999 13:44:52 -0500 (EST)
• References: <199901180922.EAA20755@smc.vnet.net.>
• Sender: owner-wri-mathgroup at wolfram.com

```Albert,
essentially the only change you have to make is to protect e.e from
being evaluated with symbols instead of numbers. (I think FindMinimum
first tries to simplify the expression.) So change the definition of e
by

e[t1_?NumericQ,t2_,l1_,l2_]:= prop-{p[t1],p[t2],pp[t2,t1,l1 l2]}

and here you are:

In:= FindMinimum[

e[t1,t2,l1,l2].e[t1,t2,l1,l2],{t1,{-.95,-.9}},{t2,{-.3,-.4}},{l1,{.4,.5}},{
l2,{.5,.6}}]

Out= {0.00002806538169368238,
{t1 -> -0.9616702160148866, t2 -> -0.3170739825593457,
l1 -> 0.9244179012730739, l2 -> 0.5000000007597158}}

As you see, I didn't bother to check the gradient, so I had to give two
start values. By the way, it took a while for Mathematica to calculate
the minimum (70 seconds), so relax.

Jurgen

Albert Maydeu-Olivares wrote:
>
> Hi, everyone
>
> I can't get FindMinimum to work when the function to be minimized
> involves numerical integrals.
> Any suggestions would be most welcome.
>
> I enclose a typical example: I'm trying to minimize     e .e where e =
>         {data1-definite integral of a univariate normal distribution,
>                 data2- definite integral of a univariate normal distribution,
>                 data3- definite integral of a bivariatye normal distribution} using
> Newton's method.
>
> Below is the code. The gradient is correct.
>
> In:=
> dens[x_]=1/(E^(x^2/2)*Sqrt[2*Pi]);
> p[h_]:=Module[{x},NIntegrate[dens[x],{x,h,Infinity}]] dens2[h_,k_,x_]=
> 1/(2*E^((h^2 + k^2 - 2*h*k*x)/(2*(1 - x^2)))*Pi*Sqrt[1 - x^2]);
> pp[h_,k_,r_]:=  Module[{x},
>     NIntegrate[dens2[h,k,x],{x,0,r},PrecisionGoal->10]+p[h] p[k]]
>
> In:=
> nvars=2;ncorr=1;
> prop={.828,.628,.567};
> t={t1,t2};
> r={l1 *l2};
>         {0,-dens[t2],0,0},
>         {dens[t1]*(-1 + Erf[(-(l1*l2*t1) + t2)/Sqrt[2 - 2*l1^2*l2^2]])/2,
>          dens[t2]* (-1 + Erf[(t1 - l1*l2*t2)/Sqrt[2 - 2*l1^2*l2^2]])/2,
>          dens2[t1,t2,l1*l2]*l2,       dens2[t1,t2,l1*l2]*l1}};
>
> In:=
> e := prop-{p[t[]],p[t[]],pp[t[],t[],r[]]} ; FindMinimum[e
> . e, {t1,-.95},{t2,-.4},{l1,.5},{l2,.6},
>
> Out=
> "Could not symbolically find the gradient of (e . e)
>  Try giving two starting values for each variable."
>
> I believe the error message given by FindMinimum is misleading.
>
> Trying to figure out what's going on, I specify the problem using
> Integrate and then
> numerically evaluating the integrals inside FindMinimum. It did not work
> either.
> It just sit there.
>
> In:=
> p2[h_]:=Integrate[dens[x],{x,h,Infinity}]
> pp2[h_,k_,r_]:=Integrate[dens2[h,k,x],{x,0,r}]+p[h] p[k]
>
> e2 := prop-{p2[t[]],p2[t[]],pp2[t[],t[],r[]]} ;
> FindMinimum[N[e2 . e2], {t1,-.95},{t2,-.4},{l1,.5},{l2,.6},
>
> --
>
> Albert Maydeu-Olivares                  Tel. +34 3 4021079 ext. 3099 Faculty of
> Psychology                      Fax. +34 3 4021362 University of Barcelona                      E-Mail:
> amaydeu at tinet.fut.es Passeig de la Vall d'Hebron, 171.
> 08035 - Barcelona (Spain)

```

• Prev by Date: Re: a tricky limit
• Next by Date: Re: Special characters
• Previous by thread: using FindMinimum to minimize a function involving NIntegrate
• Next by thread: Re: using FindMinimum to minimize a function involving NIntegrate