[ADMB Users] less-than issue in ADMB-RE? (probably boneheaded)
Ben Bolker
bbolker at gmail.com
Mon May 23 13:54:24 PDT 2011
I am trying to do something seemingly straightforward, which is not
working, therefore I suspect I am doing something stupid.
The random effects model below fails to compile with an error "no
match for 'operator<' ..."
The critical lines of code are two loops where I set a minimum value
on variables, e.g.
for (int i=1; i<=nobs; i++)
if (x1(i)<eps1) x1(i)=eps1;
and
for (int i=1; i<=nobs; i++)
if (p(i)<eps2) p(i)=eps2;
where eps1, eps2 are numbers and x1 and p are vectors (in a previous
attempt eps1 and eps2 were just numeric constants instead).
An earlier non-random-effects version of this code worked fine.
I would guess that the error message is telling me that the less-than
operator hasn't been defined for the data types I'm comparing, but at
the moment I'm finding easier to believe that I'm doing something stupid
than that "<" is not defined for the comparison of a (double precision?)
vector element and a scalar or numeric constant ...
Alternatively, has anyone written an implementation of R's 'pmax()'
function that would work here?
Error messages and full TPL file included below. I am also happy to
receive stylistic/coding suggestions ...
Apologies for any mangling of the line spacing by my mail client.
cheers
Ben Bolker
==================
*** adcomp -r weibR1_gen
g++ -c -O3 -Wno-deprecated -D__GNUDOS__ -Dlinux -DOPT_LIB -DUSE_LAPLACE
-fpermissive -I. -I/usr/local/admb/include weibR1_gen.cpp
weibR1_gen.cpp: In member function ‘virtual void
df1b2_parameters::user_function()’:
weibR1_gen.cpp:165: error: no match for ‘operator<’ in
‘((df1b2_parameters*)this)->df1b2_parameters::x1.df1b2vector::operator()(i)
< ((df1b2_parameters*)this)->df1b2_parameters::eps1’
/usr/local/admb/include/fvar.hpp:7862: note: candidates are: int
operator<(double, const prevariable&)
/usr/local/admb/include/df32fun.h:289: note: int
operator<(const df3_two_variable&, double)
/usr/local/admb/include/df32fun.h:295: note: int
operator<(const df3_two_variable&, const df3_two_variable&)
weibR1_gen.cpp:169: error: no match for ‘operator<’ in
‘((df1b2_parameters*)this)->df1b2_parameters::p.df1b2vector::operator()(i)
< ((df1b2_parameters*)this)->df1b2_parameters::eps2’
/usr/local/admb/include/fvar.hpp:7862: note: candidates are: int
operator<(double, const prevariable&)
/usr/local/admb/include/df32fun.h:289: note: int
operator<(const df3_two_variable&, double)
/usr/local/admb/include/df32fun.h:295: note: int
operator<(const df3_two_variable&, const df3_two_variable&)
============================
DATA_SECTION
init_int nobs
init_int nttt
init_matrix ttt(1,7599,1,4)
init_vector eclosed(1,7599)
init_vector avail(1,7599)
init_vector hour(1,7599)
init_vector prevhour(1,7599)
init_ivector lineind(1,7599)
init_ivector vialind(1,7599)
PARAMETER_SECTION
objective_function_value f
init_vector tttcoefs(1,4)
init_number logk
init_bounded_number starthour(210,215.99)
init_bounded_number sigma_L(1e-04,5)
init_bounded_number sigma_V(1e-04,5)
vector loglam(1,nobs)
vector lambda(1,nobs)
vector x1(1,nobs)
vector x2(1,nobs)
vector p(1,nobs)
vector u_L_sc(1,nobs)
vector u_V_sc(1,nobs)
number eps1
number eps2
random_effects_vector u_L(1,8)
random_effects_vector u_V(1,447)
LOCAL_CALCS
eps1=0.001;
eps2=1.0e-6;
PROCEDURE_SECTION
loglam=ttt*tttcoefs;
for (int i=1; i<=nobs; i++) {
loglam[i] += u_L_sc[lineind[i]]+u_V_sc[vialind[i]];
}
lambda=exp(loglam);
x1=prevhour-starthour;
for (int i=1; i<=nobs; i++)
if (x1(i)<eps1) x1(i)=eps1;
x2=hour-starthour;
p=exp(-pow(elem_div(x1,lambda),exp(logk)))-exp(-pow(elem_div(x2,lambda),exp(logk)));
for (int i=1; i<=nobs; i++)
if (p(i)<eps2) p(i)=eps2;
f-=sum(elem_prod(eclosed,log(p))+elem_prod((avail-eclosed),log(1-p)));
TOP_OF_MAIN_SECTION
arrmblsize = 2147483647;
More information about the Users
mailing list