[ADMB Users] Problems with RE model, using FUNCTIONs for integration

dave fournier davef at otter-rsch.com
Wed Dec 5 16:18:52 PST 2012


However thinking about this a bit more, it appears that
    adromb only has to pass two variables so you can use
    df1_two  and df3_two objects to do all the derivatives via forward mode.
   that wil greatly reduce the amount of temporary storage.
   at present these things are available for up to three parameters.

   There should be examples in the source if you grep on df1_two and 
df1_three.
    I don't know if there are any writeups about this but they are 
really useful when
you have a long function that takes from 1-3 variables.  The glue to the 
rest of the
derivative calculations is done automatically for you.
It looks like this

     df1b2variable log_negbinomial_density(double x, const df1b2variable 
& _xmu,
                                       const df1b2variable & _xtau)
{
    ADUNCONST(df1b2variable, xmu)
       ADUNCONST(df1b2variable, xtau)

    init_df3_two_variable mu(xmu);
    init_df3_two_variable tau(xtau);

    *mu.get_u_x() = 1.0;   // should not need this for latest code
    *tau.get_u_y() = 1.0;   // should not need this for latest code
    if (value(tau) - 1.0 < 0.0)
    {
       cerr << "tau <=1 in log_negbinomial_density " << endl;
       ad_exit(1);
    }
    df3_two_variable r = mu / (1.e-120 + (tau - 1.0));
    df3_two_variable tmp;

    tmp = gammln(x + r) - gammln(r) - gammln(x + 1)
       + r * log(r) + x * log(mu) - (r + x) * log(r + mu)

    df1b2variable tmp1;
    tmp1 = tmp;
    return tmp1;
}

In my current version all the glue is done with

   init_df3_two_variable mu(xmu);
   init_df3_two_variable tau(xtau);

at one end and

       tmp1 = tmp;

at the other end
but this may be an older version that needs an explicit

    *mu.get_u_x() = 1.0;   // should not need this for latest code
    *tau.get_u_y() = 1.0;   // should not need this for latest code





More information about the Users mailing list