[ADMB Users] Question about R2admb
Ben Bolker
bbolker at gmail.com
Thu Mar 27 08:16:32 PDT 2014
On 14-03-27 10:20 AM, Ximing Xu wrote:
> Dear Professor Bolker,
>
>
> I am using R2admb to fit a state-space model with my own TPL file.
>
> In the TPL file , we have the following function:
>
>
> SEPARABLE_FUNCTION void cond_nllo(const dvariable& deloy,const dvariable& del1y)
>
> nll += kterm + 0.5*square(deloy);
> nll += kterm + 0.5*square(del1y);
>
>
>
> where kterm is some predefined constant, and nll is the objective funtion to be minimized.
>
>
> Now I would like to change nll to be
>
>
> nll += kterm + 0.5*square(deloy)*(deloy<=1.4) with a logical operator .
>
>
> Then the TPL file can not be compiled anymore. I also found that the mathematical operations
>
> such as + - * / work for deloy but the modulus operator % does not work on it.
>
>
> Do you know if there is any way to solve this problem? Thank you very much.
>
>
>
> Best,
>
>
> Ximing
I'm not 100% sure, but I strongly suspect this is a generic ADMB
question rather than an R2admb-specific question -- that is, it would
apply whether or not you were using the R2admb interface. I'm taking
the liberty of cc'ing it there. You can probably do something like
int thresh;
thresh = (deloy <=1.4 ? 1 : 0 ); // ternary operator
or perhaps
thresh = (int)(deloy<=1.4)
(these are two standard C idioms for converting a logical expression to
a 0/1 value).
I don't know offhand why the modulus operator doesn't work, but
possibly because it is a non-differentiable operator and thus hasn't
been defined in ADMB? (I searched the ADMB manual for "modulus" and for
"%" used in this context and didn't find it ...
If you try to compile your model outside of R (i.e. using the
command-line tools rather than R2admb) and find it *does* work from the
command line but not via R2admb, feel free to bug me again.
good luck,
Ben Bolker
More information about the Users
mailing list