very poor performance of global optimization toolbox?

Hi

Just started using the global optimization toolbox. Not sure if I am doing something wrong or if it is genuinely awful. After about 20mins it produces a fit that is dreadful,an alternative cheaper package (scop) produces a great fit in about 2 mins. Can anyone see what I'm doing wrong?

 

Attached are 2 documents -fit test.mw which produces the fits (I'm fitting an ode, it is soluable analytically but in general I wont to use the toolbox for equations that arent soluable analytically so I've used the numerical solver -just as I did in scop) and comparefits.mw which compares the fit produced by maple (blue line) with the fit produced by scop (green line) to the data points (in red) -see plot at the bottom of the document.

 

Any ideas how to 1) get maple to produce decent fits 2) speed up would be v useful.

thanks

View 8402_fit test.mw on MapleNet or Download 8402_fit test.mw
View file detailsView 8402_comparefits.mw on MapleNet or Download 8402_comparefits.mw
View file details

Fit

Here is how I might approach that, using Statistics:-NonlinearFit.

T := Vector([0., 10.0, 20.0, 31.0, 41.0, 52.0, 63.0, 101.0, 118.0, 146.0, 175.0]):

Z := Vector([NULL
             , 0.26134778186274507e-1
             , 0.5998907077205882e-1
             , 0.9122613357843135e-1
             , .15470589797794115
             , .15113937469362743
             , .17105442156862743
             , .2182091648284313
             , .13516658731617642
             , .10597567371323527
             , 0.8211602236519606e-1
             , 0.7081520343137254e-1
            ]):

L := piecewise(t<=63
               , c*(F*(1-exp(-Delta*t))   + beta*exp(-Delta*t))
               , c*(F*(1-exp(-Delta*tau)) + beta*exp(-Delta*tau))*exp(-Delta*(t-tau))
              ):

GivenParams := {F=0.015,c=4.46,Delta=0.088,beta=0.007,tau=63}:

deqs := {NULL
         , -diff(y(t),t)+2*p1*f*L-p1*y(t)
         , -diff(x(t),t)+2*p2*(1-f)*L-p2*x(t)
         , x(0) = 0, y(0) = 0
        }:

dsol := dsolve(eval(deqs, GivenParams), {x,y}(t)):

z := x(t)+y(t)/2/F/c:

znum := subs(dsol, GivenParams, z);

FoundParams := Statistics:-NonlinearFit(znum,T,Z,t,output=parametervalues);

zfit := eval(znum,FoundParams);

plt_data := plot(zip(`[]`,T,Z), style=point):
plt_fit  := plot(zfit, t=0..180):

plots:-display([plt_data,plt_fit]);

This takes about 10 seconds of compute time (mostly in dsolve).

with dsolve/numeric

A limitation of my previous response is that it depended on dsolve being able to solve the differential equations symbolically.  Here is a modification that uses dsolve/numeric.  Note that I used the optional parameter 'initialvalues' in the call NonlinearFit, that was necessary to avoid a range that dsolve could not integrate.  This is slower, it takes about 45 seconds.

T := Vector([0., 10.0, 20.0, 31.0, 41.0, 52.0, 63.0, 101.0, 118.0, 146.0, 175.0]):

Z := Vector([NULL
             , 0.26134778186274507e-1
             , 0.5998907077205882e-1
             , 0.9122613357843135e-1
             , .15470589797794115
             , .15113937469362743
             , .17105442156862743
             , .2182091648284313
             , .13516658731617642
             , .10597567371323527
             , 0.8211602236519606e-1
             , 0.7081520343137254e-1
            ]):

L := piecewise(t<=63
               , c*(F*(1-exp(-Delta*t))   + beta*exp(-Delta*t))
               , c*(F*(1-exp(-Delta*tau)) + beta*exp(-Delta*tau))*exp(-Delta*(t-tau))
              ):

GivenParams := {F=0.015,c=4.46,Delta=0.088,beta=0.007,tau=63}:

deqs := {NULL
         , -diff(y(t),t)+2*p1*f*L-p1*y(t)
         , -diff(x(t),t)+2*p2*(1-f)*L-p2*x(t)
         , x(0) = 0, y(0) = 0
        }:

dsol := dsolve(eval(deqs, GivenParams), {x,y}(t), 'numeric', 'parameters'=[p1,p2,f]):

z := (x(t)+y(t))/2/F/c:
znum := eval(z, GivenParams):

zcompute := proc(t,p1,p2,f)
    dsol('parameters' = [p1,p2,f]);
    eval(znum, dsol(t));
end proc:

FoundParams := Statistics:-NonlinearFit(zcompute, T, Z
                                        , output=parametervalues
                                        , initialvalues = <.01, .001, 0.1>
                                       );

dsol('parameters' = convert(FoundParams,'list'));
plt_fit := plots[odeplot](dsol, [t, znum], 0..175):
plt_data := plot(zip(`[]`,T,Z), style=point):

plots:-display([plt_data,plt_fit]);

 

Hi Joe thanks for the reply

Hi Joe

thanks for the reply but isnt "Statistics:-NonlinearFit" a local fit? I'd be worried about local minima for more complicated problems.

acer's picture

least squares

The Statistics:-NonlinearFit help-page says that it uses a least squares approach.  It seemed straightforward to adapt Joe's (2nd) approach evaluating the DE (at a point t) to one which did a sum of squares for the data points in T and Z.

B := proc(a,b,c)
global T,Z;
local G,i;
for i from 1 to 11 do
    G[i]:=zcompute(T[i],a,b,c);
end do;
add( (G[i]-Z[i])^2, i=1..11 );
end proc:

Once one has this objective function, in can be used with the GlobalSolve routine.

As mentioned before, GlobalSolve has a a lot of options that can be adjusted to vary how it searches.

infolevel[GlobalOptimization]:=10:
Digits := trunc(evalhf(Digits)):

GlobalOptimization:-GlobalSolve(B, 0..0.2,0..0.2,0..0.5, 
   optimalitytolerance=1.0e-6, method=singlestart,
   noimprovementlimit=400, timelimit=10000,
   evaluationlimit=500000);

Quite quickly it found the triple 4.973755e-02, 1.612033e-03, 1.462690e-01 for p1, p2, and f. I forget for which values of the solver options it found something good fastest. That triple gives an ever so slightly smaller (better) residual (total error, in least-squares) when fed into the objective function B than does the result from NonlinearFit or from that other 3rd party package.

Depending on the specific problem, you might wish to set various options and have GlobalSolve search for as long as you have patience.

You asked about the 'parameters' option for dsolve/numeric. The dsolve(...,numeric) routine doesn't itself provide the numeric solution to DEs. It returns something which can subsequently be run to provide numeric values. It sets up a solver to do that, and returns a procedure (or list of such) that when run will themselves return the numeric values. But what if one has a generic DE of some form, and knows in advance that it will have to be solved numerically for various different values of some parameters (coefficients, etc) wihin it? One doesn't want to have to call all the heavy expensive machinery each time a parameter is adjusted, just to produce the solving-procedures which appear the same (except for the change in parameters). And indeed, your optimization problem seems to be a perfect example of why such efficient parametric numeric DE solving is necessary. How does it work? I don't know -- maybe it's just using Maple's lexical scoping functionality, and supplying the 'parameters' option informs dsolve/numeric that this will be OK at runtime. The option is briefly mention, but not fully described, on the ?dsolve[numeric,IVP] help-page.

acer

Hi Joe the first version

Hi Joe

the first version works very well but I couldn't get the numerical version to work (get error message -I'm using Maple 11). What is the option `parameters' that you use in dsolve?

 

thanks

acer's picture

not so awful

The awful results from this particular posted use of the GlobalOptimization toolbox are due to the fact that, as the problem was originally set up, the solver would only be able to do a relatively small number of global search evaluations before it timed out. The reason for this is because dsolve(...,numeric) was being called an enormous number of times. The act of setting up the dsolve/numeric solver was itself being done inside the objective function, at each evaluation of the objective.

Joe's responses show how the dsolve calls may be brought outside the evaluation routines, to be done just once as a set-up step.

Once the objective is made fast enough, and can run enough times to to the global optimizer a chance to do enough evaluations, it can find decent results.

I consider Joe's responses to be excellent.  I also feel that these techniques could be better documented in the product. A worksheet could illustrate the ideas nicely. And that might be usefully referenced from the help-pages of both dsolve/numeric, Optimization, and GlobalOptimization. One could construct a problem for which the numeric DE solving was involved within a root-finding problem, and thus the parametrized numeric DE solver needed to be called from fsolve.

acer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}