       Re: evaluating functions within Findminimum

• To: mathgroup at smc.vnet.net
• Subject: [mg100179] Re: evaluating functions within Findminimum
• From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
• Date: Wed, 27 May 2009 04:07:44 -0400 (EDT)
• References: <gvdr8e\$743\$1@smc.vnet.net>

```Hi Alberto,

To force numerical evaluation of your function change its argument
template slightly:

NormalAcov[matrix_?(MatrixQ[#, NumericQ] &)]

Cheers -- Sjoerd

On May 25, 12:17 pm, Alberto Maydeu <amay... at ub.edu> wrote:
> Greetings to all,
>
> I'm using
>
> FindMinimum[Evaluate[e . Inverse[NormalAcov[sigma]]. e], Evaluate[Sequenc=
e @@ startval]]
>
> NormalAcov[sigma] is a symbolic function. FindMinimum evaluates Inverse[N=
ormalAcov[sigma]] symbolically then plugs in the numeric starting values an=
d proceeds. This is obviously very slow for large problems.
>
> How can I get FindMinimum to first plug in the numeric starting values an=
d perform Inverse[NormalAcov[sigma]] numerically as opposed to symbolically=
?
>
> In case my question is unclear, here's a toy example
>
> sigma = {{l1^2 + ps1, l1* l2, l1*l3}, {l1* l2, l2^2 + ps2, l2 l3}, {l1 =
l3, l2 l3, l3^2 + ps3}};
> startval = {{l1, .8}, {l2, .7}, {l3, .6}, {ps1, 1}, {ps2, 1}, {ps3, 1}}=
;
> e = {1.7 - l1^2 - ps1, .5 - l1*l2, 1.6 - l2 - ps2, 1.5 - l1^2 - l3, .8 =
- l2*l3, 1.8 - l3^2 - ps3};
> FindMinimum[Evaluate[e . Inverse[NormalAcov[sigma]]. e], Evaluate[Sequenc=
e @@ startval]]
>
> with
>
> NormalAcov[matrix_List] := Module[{l1, l, c},
> l1 = Length[matrix];
> l = Binomial[l1 + 1, 2];
> c = Join @@ Table[{i, j}, {i, l1}, {j, 1, i }];
> Table[matrix[[c[[i, 1]], c[[j, 1]]]]*matrix[[c[[i, 2]], c[[j, 2]]]] + mat=
rix[[c[[i, 1]], c[[j, 2]]]]*matrix[[c[[i, 2]], c[[j, 1]]]]
> , {i, l}, {j, l}]];
>
> Thank you for your help.
>
> Alberto

```

• Prev by Date: Re: TRANSFER FILE NAMES
• Next by Date: Re: Keep Slider Consistent With a Slow Graph
• Previous by thread: Re: evaluating functions within Findminimum