       Re: FindMinimum slow in evaluation

• To: mathgroup at smc.vnet.net
• Subject: [mg117542] Re: FindMinimum slow in evaluation
• From: Nabeel Butt <nabeel.butt at gmail.com>
• Date: Tue, 22 Mar 2011 05:07:36 -0500 (EST)

```Just for your easy reference the code is below !!!

----start------

Clear[M, s, \[Lambda], \[CapitalDelta]T, \[Mu], m, \[Sigma], f, fc, \
mean, var, rmean, rvar, exp, sol, p, g, J]
M = 0.5;
\[Lambda] = 0.005;
\[Mu] = 0.005;
nn = 2;
T = 0.5
\[CapitalDelta]T = T/nn;
s = E^(0.05*\[CapitalDelta]T);
m = 0.08;
\[Sigma] = 0.42;
mean = (m - (\[Sigma]^2)/2)*\[CapitalDelta]T;
var = (\[Sigma]^2)*\[CapitalDelta]T;
fl[r_] := PDF[LogNormalDistribution[mean, var], r];
rmean = E^(mean + 1/2 var);
rvar = ((E^var - 1) E^(2*mean + var));
exp = {
p*(1 + g) + (1 - p)*(1/(1 + g)) == E^(mean + 1/2 var),
p*(1 + g)^2 + (1 -
p)*(1/(1 + g))^2 - (p*(1 + g) + (1 - p)*1/(1 + g))^2 == ((E^
var - 1) E^(2*mean + var))};
sol = {p, g} /. NSolve[exp, {p, g}]
p = sol[[2, 1]];
g = sol[[2, 2]];
rvals = {(1 + g), 1/(1 + g)};
pvals = {p, 1 - p};
amin = N;
amax = N;
da = 0.01;
wmin = N;
wmax = N;
dw = 0.01;
\[Gamma] = 0.5;
templist = Parallelize[
ParallelEvaluate[
Off[FindMinimum::fmgz]];
ParallelEvaluate[Off[FindMinimum::reged]];
ParallelEvaluate[Off[FindMinimum::lstol]];
Table[{{a, w},
{l =
Min[templist = {(sol1 =
FindMinimum[(((w*(s + \[Xi] (rvals - s) + \[Mu] (\[Xi] -
a) s) - \[Gamma])^2).pvals), {\[Xi], a/2, 0, a},
AccuracyGoal -> 5])[[
1]], (sol2 =
FindMinimum[(((w*(s + \[Xi] (rvals -
s) - \[Lambda] (\[Xi] -
a) s) - \[Gamma])^2).pvals), {\[Xi], (a + 1)/2, a,
1}, AccuracyGoal -> 5])[[
1]], ((w*(s + a (rvals - s)) - \[Gamma])^2).pvals}],
If[templist[] == l, 3, Flatten[Position[templist, l]][]],
Piecewise[{{0, templist[] == l}, {sol1[[2, 1, 2]],
templist[] == l}, {sol2[[2, 1, 2]],
templist[] == l}}]}}, {a, amin, amax, da}, {w, wmin,
wmax, dw}]]; // Timing
templist;
Dimensions[Flatten[templist], 1]
points = Select[
Flatten[templist,
1], #[[2, 2]] == 3 &] /. {{a_, w_}, {J_,
I_, \[CapitalDelta]_}} -> {a, w};
Graphics[Point[points], Axes -> True];
JN = Interpolation[
Flatten[templist,
1] /. {{a_, w_}, {J_, I_, \[CapitalDelta]_}} -> {{a, w}, J}];
some = NestList[{templist = Parallelize[
ParallelEvaluate[
Off[FindMinimum::fmgz]];
ParallelEvaluate[Off[FindMinimum::reged]];
ParallelEvaluate[Off[FindMinimum::lstol]];
ParallelEvaluate[Off[InterpolatingFunction::dmval]];
ParallelEvaluate[Off[FindMinimum::sdprec]];
Table[{{a, w},
{l =
Min[templist = {(sol1 =
FindMinimum[(#[][(\[Xi]*
rvals)/(s + \[Xi] (rvals - s) + \[Mu] (\[Xi] -
a) s), (w*(s + \[Xi] (rvals - s) + \[Mu] (\[Xi] -
a) s))].pvals), {\[Xi], a/2, 0, a},
AccuracyGoal -> 4])[[
1]], (sol2 =
FindMinimum[(#[][(\[Xi]*
rvals)/(s + \[Xi] (rvals - s) - \[Lambda] (\[Xi] -
a) s), (w*(s + \[Xi] (rvals -
s) - \[Lambda] (\[Xi] -
a) s))].pvals), {\[Xi], (a + 1)/2, a, 1},
AccuracyGoal -> 4])[[
1]], #[][(
a*rvals)/(s +
a (rvals - s)), (w*(s + a (rvals - s)))].pvals}],
If[templist[] == l, 3,
Flatten[Position[templist, l]][]],
Piecewise[{{0, templist[] == l}, {sol1[[2, 1, 2]],
templist[] == l}, {sol2[[2, 1, 2]],
templist[] == l}}]}}, {a, amin, amax, da}, {w, wmin,
wmax, dw}]],
Interpolation[
Flatten[templist,
1] /. {{a_, w_}, {J_, I_, \[CapitalDelta]_}} -> {{a, w},
J}]} &, {0, JN}, nn];

----------------------end------------

On Sat, Mar 19, 2011 at 6:19 AM, Nabeel Butt <nabeel.butt at gmail.com> wrote:

> Dear Users,
>          I have a program in which I am trying to minimize a
> function several times in a program.To me finding the local minimum is
> sufficient given a good intial guess and constraints.However ,
> Mathematica's
> built-in FindMinimum seems a little slow since I need to make repeated use
> of it(I tried the global minimization but it is much slower ) several times
> with different intial guesses and constraints .This depends upon the
> function too ofcourse and the time taken could be improved by changing the
> accuracy /precision. Is there a way I can get my program speeded up in
> anyway possible( Try changing the value of 'nn' in my program I upload and
> observe as 'nn' gets bigger so does the computation time needed ).I am
>                 Nabeel
>
>
> --
> "We have not succeeded in answering all our problems.The answers we have
> found only serve to raise a whole set of new questions.In some ways we feel
> that we are as confused as ever,but we believe we are confused on a higher
> level and about more important things."
> "Maybe one day we get to see all the beauty present in this world"
>
>
> Nabeel Butt
> UWO,London
>
>
>

--
"We have not succeeded in answering all our problems.The answers we have
found only serve to raise a whole set of new questions.In some ways we feel
that we are as confused as ever,but we believe we are confused on a higher
level and about more important things."
"Maybe one day we get to see all the beauty present in this world"

Nabeel Butt
UWO,London