[ADMB Users] vector powers

Skip to first unread message

Mollie Brooks

Sep 24, 2010, 11:41:57 AM9/24/10
to us...@admb-project.org
Hi all,
I was wondering, is there a function similar to "pow" that can take 2 vectors of the same length, one of bases and another of exponents, and return a vector of the bases raised to the exponents?

Ben Bolker

Sep 24, 2010, 12:09:35 PM9/24/10
to Mollie Brooks, us...@admb-project.org
  [responding to previous question about vectorizing pow() on both the bases and the exponents -- I suggested
an explicit for loop ... posting back to the list for comment/correction]

On 10-09-24 11:55 AM, Mollie Brooks wrote:
> That's what I've done, but I was hoping to be more efficient.

  I think (not positive) that encapsulating for loops in ADMB doesn't make things more efficient -- it just simplifies the code.
(If you want, I think you can write your own function -- for example, I *think* that if you put this in your GLOBALS_SECTION
it should automatically overload the "pow()" function for vectorized bases and exponents ... (based on previous contributions
from the list).

 df1b2vector pow(const df1b2vector& v,const df1b2vector & x)
    int mmin=v.indexmin();
    int mmax=v.indexmax();
   // ?? add check that vectors have the same extents ??
    df1b2vector tmp(mmin,mmax);
    for (int i=mmin;i<=mmax;i++)
    return tmp;

Poos, Jan Jaap

Oct 1, 2010, 10:46:16 AM10/1/10
to us...@admb-project.org
Following Dave Fourniers example on creating a class for likelihood profile vectors I managed to get things going. For future reference: In the example the comment "!!CLASS likeprof_vector xx(1,20,"my") // vector of 20 likeprof_numbers" got wrapped, so the example did not run initially. Thanks to Dave for pointing this out.
Now I run into new problems: if I run my model without the -lprof flag, everything runs fine (no exit code warnings). If I run it with one of my likelihood profile vectors, then everything apears to work fine, but I get an exit code 1 (which I guess is a warning for convergence problems). If I run the model with two likelihood profile vectors,  the model stops with exit code 5. I can't find in the documentattion or on the web what the different exit codes mean.
Could somebody give me pointers to where I can find the meaning of the different exit codes (or even better: hint why I get exit code 5 when trying to have two likelihood profile vectors)?
Kind regards, Jan Jaap  



dave fournier

Oct 4, 2010, 1:57:46 AM10/4/10
to us...@admb-project.org
I think it means that either there is a problem with your code or the
new stuff introduced a
bug I did not forsee. If you send me your code and whatever I need to
run the model I'll check it out.
Users mailing list

Mark Payne

Oct 5, 2010, 12:44:51 PM10/5/10
to us...@admb-project.org

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?



Richard Methot

Oct 5, 2010, 1:38:42 PM10/5/10
to Mark Payne, us...@admb-project.org
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

Derek Seiple

Oct 5, 2010, 3:14:21 PM10/5/10
to Richard Methot, us...@admb-project.org
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.


Mark Payne

Oct 6, 2010, 7:50:10 AM10/6/10
to us...@admb-project.org

That's good to hear. I was wondering though if they are there or not in the current version published on the website (9.1), as I can't seem to get access to them?

The line
generates an "out of scope" compiler error:

g++ -c -O3 -Wno-deprecated -D__GNUDOS__ -Dlinux -DOPT_LIB -DUSE_LAPLACE -fpermissive -I. -Ic:/admb/gcc440/include Forward.cpp
Forward.cpp: In member function 'virtual void model_parameters::report()':
Forward.cpp:166: error: 'spline' was not declared in this scope

Using "spine" instead of "spline" generates a corresponding error.

Running release 9.1 on Win XP.


-----Oprindelig meddelelse-----
Fra: Derek Seiple [mailto:dsei...@gmail.com]
Sendt: 5. oktober 2010 21:14
Til: Richard Methot
Cc: Mark Payne; us...@admb-project.org
Emne: Re: [ADMB Users] Interpolation while optimising

dave fournier

Oct 6, 2010, 12:34:18 PM10/6/10
to us...@admb-project.org

You are walking out of the array log_self at this line in your code.

log_self(10) = log_self(7);

You should always compile your code with the safe version of ADMB which
has bounds checking
especially if you are observing strange behaviour.

Poos, Jan Jaap

Oct 6, 2010, 5:36:05 PM10/6/10
to dave fournier, us...@admb-project.org

Indeed, and the safe mode warns for this. Thanks for pointing this out. However the model still aborts with exit code 5 if I fix this (going outside of one of my arrays. No further warnings are given in safe mode.

So my question still remains; what could be wrong, and where could I find the meaning of the exit codes.

Help is greatly appreciated.

Jan Jaap


dave fournier

Oct 6, 2010, 6:20:03 PM10/6/10
to us...@admb-project.org
If you send me the corrected code I'll check it out again.

dave fournier

Oct 7, 2010, 3:50:19 PM10/7/10
to us...@admb-project.org

ADMB works by putting objects on lists. At the time it was done
stupidly to get things done quickly. The likeprof types are put on
a static array likeprofptr which can only hold 50 items with the present
It does not check this value so you are walking out of this static array.
It is at the top of the file mod_prof.cpp

likeprof_params * likeprof_params::likeprofptr[50]; // this should be
// a resizeable array

To get you model to work a quick fix is to change this to something
bigger say 500.
you will also need to change the declaration in admodel.h.

Of course anyone is welcome to fix this properly. Isn't open source

Mark Payne

Oct 8, 2010, 11:13:35 AM10/8/10
to us...@admb-project.org
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:dsei...@gmail.com]
Sent: Tue 10/5/2010 9:14 PM
To: Richard Methot
Cc: Mark Payne; us...@admb-project.org

Poos, Jan Jaap

Oct 8, 2010, 5:31:57 PM10/8/10
to us...@admb-project.org

Indeed changing the size of the array to 500 in mod_prof.cpp and admodel.h (in combination with making some methods in admodel.h public as discussed before) and rebuilding ADMB fixed the problem.

Thanks a lot,

Jan Jaap

Ian Taylor

Oct 8, 2010, 8:01:34 PM10/8/10
to Mark Payne, us...@admb-project.org
Thanks for sharing this. Your email is now
referenced in the FAQ at
I would also add that trial and error (in lieu of
knowledge of this subject) tells me that the two
additional values that you have set to 0 in the line

vcubic_spline_function splinefn=vcubic_spline_function(splinex,spliney,0.0,0.0)

are the second derivative of the spline function
at the first and last values of splinex.

One day, the documentation will describe all this
stuff, but for now, the email record certainly helps.

Ian Taylor

Oct 8, 2010, 9:37:11 PM10/8/10
to us...@admb-project.org
Sorry, one more email.

I went ahead and posted my quick and dirty spline
testing model, associated R code, and a plot of
the fit and various resulting derivatives at
Additional examples could easily be added to that
folder, especially from folks who know how to
apply these concepts to real world problems. And
one day splines will presumably get added to the
documentation as well.

Poos, Jan Jaap

Oct 18, 2010, 5:38:17 AM10/18/10
to us...@admb-project.org


Indeed, setting the size of the list to 500 in mod_prof.cpp and admodel.h and building ADMB fixed the problem. I don't know about the costs in terms of memory use or speed of execution, but maybe it is a good idea to do this as a default in the standard ADMB code.

Building the ADMB code for windows I used mingw. This is currently not described on the admb-project.org website, despite the makefile being there. So it should be fairly straightforward to add this.

Note that the mingw makefile to all popular windows options (bcc, vc, mingw) contains a call to svn. The instructions for building on windows don't include installing a cli svn client, and cli svn clients are rarely installed by default on windows machines. That means that make will fail.

Even with a cli svn client it seems that the call to svn fails (I can't remember the exact error message). It seems to attempt to get a copy of the examples from a repository (but I may be wrong here). Those examples are already in the source (in the version 9.1 zip file), so the svn line can safely be commented out.

I hope the developers of ADMB can make some of these changes.

Cheers, Jan Jaap

-----Original Message-----
From: users-...@admb-project.org [mailto:users-...@admb-project.org] On Behalf Of dave fournier
Sent: Thursday, October 07, 2010 9:50 PM
To: us...@admb-project.org
Subject: Re: [ADMB Users] exit codes and likelihood profile vectors

Reply all
Reply to author
0 new messages