[ADMB Users] operators in ADMB or R got it wrong

Ben Bolker bolker at ufl.edu
Wed Aug 12 10:22:40 PDT 2009


  That would certainly do it for me.
  My interest is making the superficial programming level
easier: if you have to dig into the debugger then of course
you will have to deal with more nitty-gritty details.

  cheers
    Ben


dave fournier wrote:
> Ben Bolker wrote:
> 
> It should be possible to extend the tpl2* to  replace
> 
>  x %*% y  with elem_prod(x,y)
> 
> but at the debugger level you would still see elem_prod(x,y)
> 
> 
> 
>>   I don't think the R convention OR the ADMB convention are
>> wrong; they're just different.  This is a little bit like
>> arguing over assignment and equality operators: should we
>> use =, ==, :=, <- , ... ?  The point in the notes I posted was just
>> to say that this was something that R users would have to
>> watch out for (just as people moving between MATLAB and
>> R have to be careful with conventions).
>>    Based on http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
>> it doesn't look like one would be able to construct a shorthand
>> elementwise multiplication operator -- there's no convenient
>> operator (other than *) available to overload.  ".*" does exist,
>> but it means something completely different and is not overloadable (and
>> even it were would probably confuse the hell out of C++ programmers).
>>   In R one can define "%" operators (like %*% (matrix mult),
>> %o% (outer product)) -- I wonder if the ADMB superstructure
>> allows the flexibility of defining some such operators.
>>
>>   This isn't really desperately important either -- it's
>> just an aesthetic preference for being able to write
>>
>>  x .* y
>>
>> or
>>
>>   x %*% y
>>
>> instead of
>>
>>   elem_prod(x,y)
>>
>>   cheers
>>      Ben Bolker
>>
>>
>> dave fournier wrote:
>>   
>>>    It is often said that if u and v are vectors in ADMB then
>>>
>>>         u*v
>>>
>>>    should be an element-wise product because it is so in R.
>>>
>>>    What if M is a matrix?  It is useful to have
>>>
>>>       M*v
>>>
>>>    be the product of a matrix times a vector yielding another vector.
>>>
>>>    If M and N are both matrices then M*N  should be matrix
>>>    multiplication.  If M represents a quadratic form then
>>>
>>>        u*M*v
>>>
>>>    should be the usual number obtained by  u * (M *n)
>>>
>>>     and
>>>
>>>            u*M*inv(M)*v  should be equal to  u * Id *v  = u*v
>>>
>>>    All of this speaks to the fact that u*v should be the dot product and
>>> R got it wrong.
>>>
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 


-- 
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bolker at ufl.edu / www.zoology.ufl.edu/bolker
GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://lists.admb-project.org/pipermail/users/attachments/20090812/bf58d41d/attachment.pgp>


More information about the Users mailing list