model C++ compiling error

623 views
Skip to first unread message

Chris Carleton

unread,
Sep 15, 2017, 4:44:41 PM9/15/17
to nimble-users
Hi All,

I'm trying to create a Poisson time series model in nimble. I'm able to create the model and simulate/calculate variables and parameters while it's still in R code, but when trying to compile to C++ I'm getting an error about eigenizing the model:



Warning, in eigenizing model_mu[1] the [ is still there but nDim is not 0 (not a scalar).Warning, in eigenizing model_mu[getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,1)] the [ is still there but nDim is not 0 (not a scalar).

I've posted the code I'm working on first followed by the detailed compiler output (using showCompilerOutput = TRUE). It looks like I might have to define A (precision matrix) outside the model and pass it in—the compiler seems to be complaining about it—but I don't see what's wrong with mu[1].

I'm running Mac OS X 10.12.6. Any help would be greatly appreciated.

The code:

#create some data
pois_means0
<- rgamma(1,1,10)
pois_means
<- c(pois_means0)
X1
<- matrix(rnorm(20,0,1),byrow=F)
X2
<- matrix(rnorm(20,0,1),byrow=F)
X
<- cbind(X1,X2)
B0
<- 0
K
<- ncol(X)
B
<- matrix(rnorm(ncol(X),0,1))
eta
<- rnorm(20,0,1)
for(j in 2:20){
   pois_means
[j] <- pois_means[j-1] * exp(B0 + X[j,1:K] %*% B[1:K]) * exp(eta[j])
}
counts
<- rpois(20,pois_means)


poisTSCode
<- nimbleCode({
   A
[1:K,1:K] <- inverse(diag(x=rep(1000,K),K,K))
   cholA
[1:K,1:K] <- chol(A[1:K,1:K])
   multimu
[1:K] <- rep(0,K)
   B0
~ dnorm(0,1000)
   B
[1:K] ~ dmnorm(mean=multimu[1:K], prec=cholA[1:K,1:K])
   mu0
~ dgamma(a,b)
   mu
[1:T] <- array(0,dim=T)
   mu
[1] <- mu0 * exp(B0 + X[1,1:K] %*% B[1:K])
   
for (j in 2:T){
      eta
[j] ~ dnorm(0,1000)
      mu
[j] <- mu[j-1] * exp(B0 + X[j,1:K] %*% B[1:K]) * exp(eta[j])
   
}
   
for (j in 1:T){
      Y
[j] ~ dpois(mu[j])
   
}
})


poisTSData
<- list(Y=counts,
                  X
=X)


poisTSConsts
<- list(T=length(counts),
                     K
=ncol(X))


poisTSInits
<- list(a=1,
                     b
=10,
                     B0
=0,
                     B
=matrix(c(0,0)),
                     eta
=dnorm(length(counts),0,1000)),
                     mu0
=dgamma(1,10))


poisTSModel
<- nimbleModel(code=poisTSCode,
                        data
=poisTSData,
                        inits
=poisTSInits,
                        constants
=poisTSConsts)


#compile nimble model to C++ code—much faster runtime
C_poisTSModel
<- compileNimble(poisTSModel, showCompilerOutput = TRUE)

Full compiler output:

C_poisTSModel <- compileNimble(poisTSModel, showCompilerOutput = TRUE)
compiling
... this may take a minute. On some systems there may be some compiler warnings that can be safely ignored.
Warning, in eigenizing model_mu[1] the [ is still there but nDim is not 0 (not a scalar).
Warning, in eigenizing model_mu[getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,1)] the [ is still there but nDim is not 0 (not a scalar).
clang
++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DR_NO_REMAP -I  -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/usr/local/include   -fPIC  -Wall -g -O2  -c P_4_code.cpp -o P_4_code.o
warning
: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
clang
++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DR_NO_REMAP -I  -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/usr/local/include   -fPIC  -Wall -g -O2  -c P_4_code_nfCode.cpp -o P_4_code_nfCode.o
warning
: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-missing-declarations'? [-Wunknown-warning-option]
P_4_code_nfCode
.cpp:18:36: error: no matching function for call to 'diagonal'
(Eig_model_A).block(0, 0, 2, 2) = (nimDiagonalD(nimRepd(1000, 2, 1), 2, 2)).inverse();
                                   
^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/nimble/nimbleEigen.h:189:22: note: expanded from macro 'nimDiagonalD'
#define nimDiagonalD diagonal_impl<MatrixXd>::diagonal
                     
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/nimble/nimbleEigen.h:183:85: note: candidate function template not viable: requires single argument 's', but 3 arguments were provided
 
static CwiseNullaryOp<diagonalClass<IndexReturn, DerivedSource >, returnDerived > diagonal(const DerivedSource &s) {
                                                                                   
^
P_4_code_nfCode
.cpp:1468:35: error: no viable overloaded '='
(Eig_model_mu).block(0, 0, 20, 1) = ARG1_INDEXEDNODEINFO__.info[0];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/MatrixBase.h:139:14: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const double') to 'const Eigen::MatrixBase<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false> >' for 1st argument
   
Derived& operator=(const MatrixBase& other);
             
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/MapBase.h:284:14: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const double') to 'const Eigen::MapBase<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, 1>' for 1st argument
   
Derived& operator=(const MapBase& other)
             
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/Block.h:111:5: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const double') to 'const Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>' for 1st argument
    EIGEN_INHERIT_ASSIGNMENT_OPERATORS
(Block)
   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:839:53: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_OPERATORS'
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:821:52: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR'
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/Block.h:161:5: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const double') to 'const Eigen::BlockImpl<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false, Eigen::Dense>' for 1st argument
    EIGEN_INHERIT_ASSIGNMENT_OPERATORS
(BlockImpl)
   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:839:53: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_OPERATORS'
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:821:52: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR'
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/Block.h:341:5: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const double') to 'const Eigen::internal::BlockImpl_dense<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false, true>' for 1st argument
    EIGEN_INHERIT_ASSIGNMENT_OPERATORS
(BlockImpl_dense)
   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:839:53: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_OPERATORS'
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:821:52: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR'
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/MatrixBase.h:150:14: note: candidate template ignored: could not match 'EigenBase<type-parameter-0-0>' against 'const double'
   
Derived& operator=(const EigenBase<OtherDerived>& other);
             
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/MatrixBase.h:154:14: note: candidate template ignored: could not match 'ReturnByValue<type-parameter-0-0>' against 'const double'
   
Derived& operator=(const ReturnByValue<OtherDerived>& other);
             
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/Block.h:111:5: note: candidate template ignored: could not match 'DenseBase<type-parameter-0-0>' against 'const double'
    EIGEN_INHERIT_ASSIGNMENT_OPERATORS
(Block)
   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:839:53: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_OPERATORS'
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
                                                   
^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/util/Macros.h:823:52: note: expanded from macro 'EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR'
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
                                                   
^
P_4_code_nfCode
.cpp:1588:17: error: assigning to 'Scalar' (aka 'double') from incompatible type 'typename internal::enable_if<true, const CwiseBinaryOp<internal::scalar_product_op<typename internal::promote_scalar_arg<Scalar, double, (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<double, Scalar, Eigen::internal::scalar_product_op<double, Scalar> > >::value)>::type, typename internal::traits<CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > > >::Scalar>, const typename internal::plain_constant_type<CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > >, typename internal::promote_scalar_arg<Scalar, double, (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<double, Scalar, Eigen::internal::scalar_product_op<double, Scalar> > >::value)>::type>::type, const CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > > > >::type' (aka 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Array<double, -1, -1, 0, -1, -1> >, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_exp_op<double>, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Array<double, -1, -1, 0, -1, -1> >, const Eigen::ArrayWrapper<const Eigen::Product<Eigen::Transpose<Eigen::Transpose<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false> > >, Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, 0> > > > >')
Eig_model_mu[0] = (**model_mu0)[0] * ((**model_B0)[0] + ((((Eig_model_X).block(0, 0, 1, 2)).transpose()).transpose() * ((Eig_model_B).block(0, 0, 2, 1))).array()).exp();
               
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
P_4_code_nfCode
.cpp:1914:52: error: assigning to 'Scalar' (aka 'double') from incompatible type 'typename internal::enable_if<true, const CwiseBinaryOp<internal::scalar_product_op<typename internal::traits<CwiseBinaryOp<scalar_product_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > > > >::Scalar, typename internal::promote_scalar_arg<Scalar, double, (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<Scalar, double, Eigen::internal::scalar_product_op<Scalar, double> > >::value)>::type>, const CwiseBinaryOp<scalar_product_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > > >, const typename internal::plain_constant_type<CwiseBinaryOp<scalar_product_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const CwiseUnaryOp<scalar_exp_op<double>, const CwiseBinaryOp<scalar_sum_op<double, double>, const CwiseNullaryOp<scalar_constant_op<double>, const Array<double, -1, -1, 0, -1, -1> >, const ArrayWrapper<const Product<Transpose<Transpose<Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false> > >, Block<Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0> >, -1, -1, false>, 0> > > > >, typename internal::promote_scalar_arg<Scalar, double, (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<Scalar, double, Eigen::internal::scalar_product_op<Scalar, double> > >::value)>::type>::type> >::type' (aka 'const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Array<double, -1, -1, 0, -1, -1> >, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_exp_op<double>, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Array<double, -1, -1, 0, -1, -1> >, const Eigen::ArrayWrapper<const Eigen::Product<Eigen::Transpose<Eigen::Transpose<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false> > >, Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, 0> > > > >, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Array<double, -1, -1, 0, -1, -1> > >')
Eig_model_mu[(ARG1_INDEXEDNODEINFO__.info[0]) - 1] = ((**model_mu)[(ARG1_INDEXEDNODEINFO__.info[1]) - 1] * ((**model_B0)[0] + ((((Eig_model_X).block(ARG1_INDEXEDNODEINFO__.info[0] - 1, 0, 1, 2)).transpose()).transpose() * ((Eig_model_B).block(0, 0, 2, 1))).array()).exp()) * exp((**model_eta)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1]);
                                                   
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from P_4_code_nfCode.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/nimble/EigenTypedefs.h:3:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/Core:413:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include/Eigen/src/Core/DenseCoeffsBase.h:407:27: error: no member named 'THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD' in 'Eigen::internal::static_assertion<false>'
                          THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD
)
                         
^
P_4_code_nfCode
.cpp:1588:13: note: in instantiation of member function 'Eigen::DenseCoeffsBase<Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, 1>::operator[]' requested here
Eig_model_mu[0] = (**model_mu0)[0] * ((**model_B0)[0] + ((((Eig_model_X).block(0, 0, 1, 2)).transpose()).transpose() * ((Eig_model_B).block(0, 0, 2, 1))).array()).exp();
           
^
Error: Failed to create the shared library
1 warning and 5 errors generated.
make
: *** [P_4_code_nfCode.o] Error 1


Perry de Valpine

unread,
Sep 15, 2017, 5:24:12 PM9/15/17
to Chris Carleton, nimble-users
Hi Chris,

Please try the following code (see comments for explanations):

poisTSCode <- nimbleCode({
    A[1:K,1:K] <- inverse(diag(x = rep(1000,K))) ## nimble version of diag does not accept (or need) more arguments here
   cholA[1:K,1:K] <- chol(A[1:K,1:K])
   multimu[1:K] <- rep(0,K)
   B0 ~ dnorm(0, sd = 1000)  ## Note that BUGS parameterization defaults to precision, so you must indicate if you mean std. deviation.
   B[1:K] ~ dmnorm(mean=multimu[1:K], prec=cholA[1:K,1:K])
   mu0 ~ dgamma(a,b)
##   mu[1:T] <- array(0,dim=T)                                  ## It is not valid to declare elements of mu multiple times, so this is not necessary or allowed given that the meaningful declarations are below.
##   mu[1] <- mu0 * exp(B0 + X[1,1:K] %*% B[1:K]) ## The type of the expression on the right-hand size is a matrix, so it cannot be assigned to a scalar.
   mu[1] <- mu0 * exp(B0 + inprod(X[1,1:K], B[1:K]))  ## This works because inprod returns a scalar.
   for (j in 2:T){
      eta[j] ~ dnorm(0, sd = 1000)  ## See comment above.
      ##mu[j] <- mu[j-1] * exp(B0 + X[j,1:K] %*% B[1:K]) * exp(eta[j]) ## See explanation above
      mu[j] <- mu[j-1] * exp(B0 + inprod(X[j,1:K], B[1:K])) * exp(eta[j])
   }
   for (j in 1:T){
      Y[j] ~ dpois(mu[j])
   }
})

-Perry

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users+unsubscribe@googlegroups.com.
To post to this group, send email to nimble...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/04fccb7c-cc1d-40cb-a1fc-dcffa7205e6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Carleton

unread,
Sep 15, 2017, 7:49:45 PM9/15/17
to nimble-users
Hi Perry,

Thanks again for the incredibly prompt reply. I really appreciate your help.

The code edits you made cleaned things up and the model appears to be working in R—at least I can run up to 1000 or so iterations of the MCMC in about 10–15 minutes without errors and the output makes some sense. But, the compiler is still throwing a few errors—they're cryptic to me so I'm having difficulty troubleshooting. It's something about "no member named 'block' in 'NimArr<2, double>'"

Anything you can suggest would be greatly appreciated.

Here are the errors:

> C_poisTSModel <- compileNimble(poisTSModel, showCompilerOutput = TRUE)
compiling
... this may take a minute. On some systems there may be some compiler warnings that can be safely ignored.

clang
++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DR_NO_REMAP -I  -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/usr/local/include   -fPIC  -Wall -g -O2  -c P_6_code.cpp -o P_6_code.o
warning
: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
clang
++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DR_NO_REMAP -I  -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/usr/local/include   -fPIC  -Wall -g -O2  -c P_6_code_nfCode.cpp -o P_6_code_nfCode.o
warning
: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-missing-declarations'? [-Wunknown-warning-option]
P_6_code_nfCode
.cpp:1466:82: error: no member named 'block' in 'NimArr<2, double>'
(**model_mu)[0] = ((**model_mu0)[0] * exp((**model_B0)[0] + inprod(((**model_X)).block(1, nimSeqByD(1,2,1,0)), ((**model_B)).block(nimSeqByD(1,2,1,0))))) * exp((**model_eta)[0]);
                                                                   
~~~~~~~~~~~~~ ^
P_6_code_nfCode
.cpp:1466:126: error: no member named 'block' in 'NimArr<1, double>'
(**model_mu)[0] = ((**model_mu0)[0] * exp((**model_B0)[0] + inprod(((**model_X)).block(1, nimSeqByD(1,2,1,0)), ((**model_B)).block(nimSeqByD(1,2,1,0))))) * exp((**model_eta)[0]);
                                                                                                               
~~~~~~~~~~~~~ ^
P_6_code_nfCode
.cpp:1787:151: error: no member named 'block' in 'NimArr<2, double>'
(**model_mu)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1] = ((**model_mu)[(ARG1_INDEXEDNODEINFO__.info[1]) - 1] * exp((**model_B0)[0] + inprod(((**model_X)).block(ARG1_INDEXEDNODEINFO__.info[0], nimSeqByD(1,2,1,0)), ((**model_B)).block(nimSeqByD(1,2,1,0))))) * exp((**model_eta)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1]);
                                                                                                                                       
~~~~~~~~~~~~~ ^
P_6_code_nfCode
.cpp:1787:224: error: no member named 'block' in 'NimArr<1, double>'
(**model_mu)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1] = ((**model_mu)[(ARG1_INDEXEDNODEINFO__.info[1]) - 1] * exp((**model_B0)[0] + inprod(((**model_X)).block(ARG1_INDEXEDNODEINFO__.info[0], nimSeqByD(1,2,1,0)), ((**model_B)).block(nimSeqByD(1,2,1,0))))) * exp((**model_eta)[(ARG1_INDEXEDNODEINFO__.info[0]) - 1]);
                                                                                                                                                                                                                 
~~~~~~~~~~~~~ ^
1 warning and 4 errors generated.
Error: Failed to create the shared library
make
: *** [P_6_code_nfCode.o] Error 1

Thanks again,

Chris

PS Here's the model code in case this helps:

poisTSCode <- nimbleCode({
   A
[1:K,1:K] <- inverse(diag(x=rep(1000,K)))

   cholA
[1:K,1:K] <- chol(A[1:K,1:K])
   multimu
[1:K] <- rep(0,K)
   B0
~ dnorm(0,sd=1000)

   B
[1:K] ~ dmnorm(mean=multimu[1:K], prec=cholA[1:K,1:K])
   mu0
~ dgamma(a,b)

   mu
[1] <- mu0 * exp(B0 + inprod(X[1,1:K], B[1:K])) * exp(eta[1])

   
for (j in 2:T){

      eta
[j] ~ dnorm(0,sd=1000)

      mu
[j] <- mu[j-1] * exp(B0 + inprod(X[j,1:K], B[1:K])) * exp(eta[j])
   
}
   
for (j in 1:T){
      Y
[j] ~ dpois(mu[j])
   
}
})



poisTSData
<- list(Y=counts,

                  X
=X)


poisTSConsts
<- list(T=length(counts),
                     K
=ncol(X))


poisTSInits
<- list(a=1,
                     b
=10,
                     B0
=0,

                     B
=matrix(c(0,2.5)),
                     eta
=rnorm(length(counts),0,1),
                     mu0
=rgamma(1,1,10))



poisTSModel
<- nimbleModel(code=poisTSCode,
                        data
=poisTSData,
                        inits
=poisTSInits,
                        constants
=poisTSConsts)


#compile nimble model to C++ code—much faster runtime
C_poisTSModel
<- compileNimble(poisTSModel, showCompilerOutput = TRUE)
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.

Chris Carleton

unread,
Sep 16, 2017, 12:22:01 AM9/16/17
to nimble-users
Just a quick update. I found a ticket on GitHub (https://github.com/nimble-dev/nimble/pull/566) for issue #538 and some related issues that pertain to the compiler error. According to the thread, Perry and/or the dev team resolved it. So, I installed from the dev source from GitHub instead of the CRAN package and the issue is indeed resolved. The compiler works just fine now. Thanks, Perry and the rest for all your hard work!

Chris

Perry de Valpine

unread,
Sep 16, 2017, 12:15:48 PM9/16/17
to Chris Carleton, nimble-users
Fantastic.  Thanks for digging into that, Chris.  I was just going to sit-down and see if that was the situation.  

We aim to release a new version in the next month or so that should include that bug fix.  In the meantime, installing from our devel branch on github is the way to go.

For any other readers wanting to do so, here is how you can, without needing to clone the github repository:

library(devtools)
install_github("nimble-dev/nimble", ref = "devel", subdir = "packages/nimble")

-Perry


To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users+unsubscribe@googlegroups.com.

To post to this group, send email to nimble...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages