[ADMB Users] Question about R2admb

Ximing Xu Ximing.Xu at Dal.Ca
Thu Mar 27 12:19:17 PDT 2014

Dear Professor Fournier,

Thanks for your answer. Yes, the density function I am trying to use is Huber's least favorable distribution which is 
piece wise and not differentiable at two cutoff points ( -k< x < k ).   Will ADMB work for it ? If not, I will consider using 
some smoothed approximation to Huber's density function. 

A more general question is:   deloy is defined  by  dvariable or const dvariable&,   how should I define x (cosnt double  or something else) 
 such that the logical operator (deloy < x ) or the if statement if (deloy >x ) will work?  Thanks.


From: users-bounces at admb-project.org <users-bounces at admb-project.org> on behalf of users-request at admb-project.org <users-request at admb-project.org>
Sent: Thursday, March 27, 2014 7:00 PM
To: users at admb-project.org
Subject: Users Digest, Vol 65, Issue 6

Send Users mailing list submissions to
        users at admb-project.org

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
        users-request at admb-project.org

You can reach the person managing the list at
        users-owner at admb-project.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Users digest..."

Today's Topics:

   1. Re: Question about R2admb (Ben Bolker)
   2. Re: Question about R2admb (dave fournier)


Message: 1
Date: Thu, 27 Mar 2014 11:16:32 -0400
From: Ben Bolker <bbolker at gmail.com>
To: Ximing Xu <Ximing.Xu at Dal.Ca>
Cc: users at admb-project.org
Subject: Re: [ADMB Users] Question about R2admb
Message-ID: <533440D0.2050005 at mcmaster.ca>
Content-Type: text/plain; charset=ISO-8859-1

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


Message: 2
Date: Thu, 27 Mar 2014 09:34:06 -0700
From: dave fournier <davef at otter-rsch.com>
To: users at admb-project.org
Subject: Re: [ADMB Users] Question about R2admb
Message-ID: <533452FE.2000707 at otter-rsch.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

>  nll += kterm + 0.5*square(deloy)*(deloy<=1.4)   with a logical operator

This looks to be non differentiable.  ADMB has the  posfun function to
enable the user
to approximate sharp cutoff points with smooth ones


Users mailing list
Users at admb-project.org

End of Users Digest, Vol 65, Issue 6

More information about the Users mailing list