[ADMB Users] Interpolation while optimising

Mark Payne mpa at aqua.dtu.dk
Fri Oct 8 08:13:35 PDT 2010


For future reference, here is the answer courtesy of Derek (with a few edits from me).

The spline system in ADMB is based around a class called vcubic_spline_function. The way these classes work is when you declare something of type
vcubic_spline_function it automatically calls spline() to set up things for splint(). Then when you make a call to the type you just set up it calls splint() to do the interpolation. The class hides these details. so for example you might have something like this:

vcubic_spline_function interp_func(x, y, dfl, dfr);  // this calls spline() behind the scenes
interpolated_val = interp_func( some_x_val );
other_interp_val = interp_func( some_other_x_val ); // this calls splint() behind the scenes

And here's an example from my procedure section:

 dvector splinex(1,nages);
 dvar_vector spliney(1,nages);

 //... Populate splinex and spliney ...//

 //Create the class
 vcubic_spline_function splinefn=vcubic_spline_function(splinex,spliney,0.0,0.0);

 //Evaluate the function
 interpolated= splinefn(0.1);


 


-----Original Message-----
From: Derek Seiple [mailto:dseiple84 at gmail.com]
Sent: Tue 10/5/2010 9:14 PM
To: Richard Methot
Cc: Mark Payne; users at admb-project.org
Subject: Re: [ADMB Users] Interpolation while optimising
 
I have replaced those functions that you mentioned ( spine() and
splint() ). They are still in the replacement branch but they will be
merged into the trunk soon. The names will be the same and they should
produce the same output as the old ones. They will be replaced with
the new beta release.

Derek

On Tue, Oct 5, 2010 at 7:38 AM, Richard Methot <Richard.Methot at noaa.gov> wrote:
> When I need to join two discontinuous functions in a differentiable way, I
> do something like:
>
>  f1(x)  for x<X
>  f2(x)  for x>=X
>  steep=10.;  // or larger value depending on expected magnitude of x-X
>  join(x) =1./(1.+mfexp(steep*(x-X))));  // so is steep and centered on X
>
> // composite function is then
>  f(x) = f1(x)*join(x) + f2(x)*(1.-join(x));
>
>  this is not perfect and depending on the slope of f1 and f2 near X may
> result in a small wrinkle in the composite function, but it has served my
> purposes.
>
> Rick Methot
>
> Mark Payne wrote:
>>
>> Hi,
>>
>> I have been wondering about this for quite some time. What is the
>> "correct" way to do  interpolation in ADMB, so that you don't run into
>> problems with discontinuous gradients? I see that there are a series of
>> cubic spline interpolation functions in there, spine(), splint() but that
>> they are also marked for replacement. Is there something else in the works
>> or is this the best approach?
>>
>> Cheers,
>>
>> Mark
>> _______________________________________________
>> Users mailing list
>> Users at admb-project.org
>> http://lists.admb-project.org/mailman/listinfo/users
>>
>
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users
>








More information about the Users mailing list