Closed syclik closed 8 years ago
From @ksvanhorn on March 19, 2015 18:9
Here are the stan models I'm using:
data {
int<lower=0> K; // # of product covariates; no intercept
int<lower=0> G; // # of respondent covariates
int<lower=0> S; // # of scenarios per respondent
int<lower=0> C; // # of alternatives (choices) per scenario
matrix[C, K] X[S]; // X[s] is covariate matrix of scenario s for respondent.
vector[G] Z; // vector of covariates describing respondent r
int<lower=1,upper=C> Y1[S]; // forced-choice responses
real<lower=0,upper=1> Y2[S]; // whether respondent would choose any of the options
int<lower=0> n_shared;
int<lower=0, upper=1> use_quad_form;
matrix[n_shared, n_shared] S_mat;
vector[n_shared] mu;
}
transformed data {
int n_preTheta;
int<lower=0, upper=0> n_shared_check;
n_preTheta <- (K + 1) * G;
n_shared_check <- n_shared - (1 + (K + 1) + n_preTheta);
}
parameters {
real logit_lambda;
vector[K+1] log_sigma;
matrix[K+1, G] preTheta;
vector[K+1] Epsilon;
}
transformed parameters {
}
model {
real lambda;
vector[K+1] sigma;
lambda <- inv_logit(logit_lambda);
for (i in 1:(K+1))
sigma[i] <- exp(log_sigma[i]);
Epsilon ~ normal(0, 1);
{
vector[S] ll;
vector[K+1] Beta;
Beta <- 10.0* preTheta * Z + (sigma .* Epsilon);
{
vector[K] b;
real alpha2;
b <- segment(Beta, 2, K);
alpha2 <- Beta[1];
for (s in 1:S) {
vector[C] u;
real u_buy;
u <- X[s] * b;
u_buy <- alpha2 + lambda * log_sum_exp(u);
ll[s] <-
categorical_logit_log(Y1[s], u) +
Y2[s] * binomial_logit_log(1, 1, u_buy) +
(1 - Y2[s]) * binomial_logit_log(0, 1, u_buy);
}
}
increment_log_prob(ll);
}
if (use_quad_form) {
vector[n_preTheta] vec_preTheta;
vector[n_shared] shparms;
int idx;
vec_preTheta <- to_vector(preTheta);
idx <- 1;
shparms[idx] <- logit_lambda; idx <- idx + 1;
for (i in 1:(K+1)) {
shparms[idx] <- log_sigma[i]; idx <- idx + 1;
}
for (i in 1:n_preTheta) {
shparms[idx] <- vec_preTheta[i]; idx <- idx + 1;
}
increment_log_prob(-0.5 * quad_form(S_mat, shparms - mu));
}
}
generated quantities {
}
and this:
data {
int<lower=0> K; // # of product covariates; no intercept
int<lower=0> G; // # of respondent covariates
int<lower=0> n_shared;
int<lower=0, upper=1> use_quad_form;
matrix[n_shared, n_shared] S_mat;
vector[n_shared] mu;
}
transformed data {
int n_preTheta;
int<lower=0, upper=0> n_shared_check;
n_preTheta <- (K + 1) * G;
n_shared_check <- n_shared - (1 + (K + 1) + n_preTheta);
}
parameters {
real logit_lambda;
vector[K+1] log_sigma;
matrix[K+1, G] preTheta;
}
transformed parameters {
}
model {
real lambda;
vector[K+1] sigma;
lambda <- inv_logit(logit_lambda);
//lambda ~ uniform(0, 1);
increment_log_prob(-2 * log1p_exp(-logit_lambda) - logit_lambda);
for (i in 1:(K+1))
sigma[i] <- exp(log_sigma[i]);
sigma ~ normal(0, 5.0);
increment_log_prob(log_sigma);
{
vector[n_preTheta] vec_preTheta;
vec_preTheta <- to_vector(preTheta);
vec_preTheta ~ normal(0, 1);
if (use_quad_form) {
vector[n_shared] shparms;
int idx;
idx <- 1;
shparms[idx] <- logit_lambda; idx <- idx + 1;
for (i in 1:(K+1)) {
shparms[idx] <- log_sigma[i]; idx <- idx + 1;
}
for (i in 1:n_preTheta) {
shparms[idx] <- vec_preTheta[i]; idx <- idx + 1;
}
increment_log_prob(-0.5 * quad_form(S_mat, shparms - mu));
}
}
}
generated quantities {
}
[Arrg! I hate that github won't let you attach text files to an issue!]
I'm using the models in two ways: 1) doing optimization, with use_quad_form = TRUE, and 2) computing a Hessian at a particular point by calling sampling() with use_quad_form = FALSE in the data, and test_grad=TRUE.
From @ksvanhorn on March 19, 2015 20:0
I found out a little bit more about the failures that output no error message. I happened to learn about the geterrmessage() function, so I used this to find out what the error was that didn't get printed out. The result I got was
[1] "Error in Module(module, mustStart = TRUE) : \n Failed to initialize module pointer: Error in FUN(\"_rcpp_module_boot_stan_fit4model10b0105af_nested_hmnl_lp_ind_mod\"[[1L]], : no such symbol _rcpp_module_boot_stan_fit4model10b0105af_nested_hmnl_lp_ind_mod in package C:/Users/KevinV/AppData/Local/Temp/RtmpygPQD8/file10b077de71d4.dll\n"
This is an error message that I have seen sporadically before.
Have you restarted after installation? I've seen that after installing without a restart, but it may still happen after a restart. On Mar 19, 2015 4:00 PM, "Kevin S. Van Horn" notifications@github.com wrote:
I found out a little bit more about the failures that output no error message. I happened to learn about the geterrmessage() function, so I used this to find out what the error was that didn't get printed out. The result I got was
[1] "Error in Module(module, mustStart = TRUE) : \n Failed to initialize module pointer: Error in FUN(\"_rcpp_module_boot_stan_fit4model10b0105af_nested_hmnl_lp_ind_mod\"[[1L]], : no such symbol _rcpp_module_boot_stan_fit4model10b0105af_nested_hmnl_lp_ind_mod in package C:/Users/KevinV/AppData/Local/Temp/RtmpygPQD8/file10b077de71d4.dll\n"
This is an error message that I have seen sporadically before.
— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1400#issuecomment-83740207.
From @ksvanhorn on March 19, 2015 20:54
It's possible that last error occurred after installing 2.6.0 and before a restart, but I can't say for sure. That would account for one of the odd behaviors I've seen.
From @ksvanhorn on March 19, 2015 21:24
OK, I just saw that "Failed to initialize module pointer" error again, and I had definitely restarted R more than once since installing 2.6.0. Again, one of the oddities was that the error message didn't actually get printed out when the failure occurred; I had to use geterrmessage() to see it.
From @sakrejda on March 19, 2015 21:53
What do you get with options (error=recover) set? On Mar 19, 2015 5:24 PM, "Kevin S. Van Horn" notifications@github.com wrote:
OK, I just saw that "Failed to initialize module pointer" error again, and I had definitely restarted R more than once since installing 2.6.0. Again, one of the oddities was that the error message didn't actually get printed out when the failure occurred; I had to use geterrmessage() to see it.
— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1400#issuecomment-83764385.
From @bob-carpenter on March 19, 2015 22:45
Which R interface (Rstudio, GUI, terminal) on which platform (linux, Mac, windows) and which C++ compiler?
On Mar 20, 2015, at 8:24 AM, Kevin S. Van Horn notifications@github.com wrote:
OK, I just saw that "Failed to initialize module pointer" error again, and I had definitely restarted R more than once since installing 2.6.0. Again, one of the oddities was that the error message didn't actually get printed out when the failure occurred; I had to use geterrmessage() to see it.
— Reply to this email directly or view it on GitHub.
From @maverickg on March 19, 2015 23:17
On Thu, Mar 19, 2015 at 11:00:23AM -0700, Kevin S. Van Horn wrote:
I have been seeing some strange behavior from rstan that I have not been able to boil down to a simple case, as it's a "Heisenbug" -- problems come and go with seemingly inconsequential changes to my program, including adding print statements or running the debugger. Nor do the problems seem to be entirely repeatable.
Here is one error message I got from stan_model (the traceback indicates that it was calling stanc):
Error in .Call("CPP_stanc260", model_code, model_cppname) : "CPP_stanc260" not resolved from current namespace (rstan
I cannot think of a reason this would happen. CPP_stanc260 is a function compiled in rstan package (i.e., in rstan.so/dll), which should always be found.
Another common symptom is to call a function
lpres <- the.function(data, inits, tol)
where the.function() includes calls to various rstan functions (stan_model and sampling), whereupon the call to the.function() fails at a point that appears to be a call to an rstan function, but no error message is ever output. The only reason I know the function fails is that nothing gets assigned to lpres, and expected console output is never produced.
On another occasion an rstan call caused R itself to outright crash. The crash might be due to that the dynamic share object (or DLL) somehow gets unloaded. I cannot think of a reason now why it happens. It would be nice we have a replicable example. Otherwise, it's going to be very hard to figure out.
I've encountered these problems with both rstan 2.5 and rstan 2.6, and on two different machines.
I will add more information as I continue investigating this.
Reply to this email directly or view it on GitHub: https://github.com/stan-dev/stan/issues/1400
From @bgoodri on March 20, 2015 0:54
I'm going to guess .RData file autoloaded on startup with objects created by a previous version of RStan.
From @bob-carpenter on March 21, 2015 0:43
This is an RStan issue, not a Stan issue, so it's in the wrong issue tracker. Each interface has its own issue tracker for interface-specific issues.
Could someone either move this or track when it's dealt with so it doesn't linger here?
Is any of this still happening with rstan 2.9.0 from CRAN?
I had this pop up after deciding to use stan_model
followed by sampling
, instead of just using stan
.
I was using 2.8.x (.2?); so I read this, removed the package, installed 2.9.0, and restarted R. The problem disappeared.
Not sure if it was upgrading, restarting R, or both that solved it for my particular case.
From @ksvanhorn on March 19, 2015 18:0
I have been seeing some strange behavior from rstan that I have not been able to boil down to a simple case, as it's a "Heisenbug" -- problems come and go with seemingly inconsequential changes to my program, including adding print statements or running the debugger. Nor do the problems seem to be entirely repeatable.
Here is one error message I got from stan_model (the traceback indicates that it was calling stanc):
Another common symptom is to call a function
where the.function() includes calls to various rstan functions (stan_model and sampling), whereupon the call to the.function() fails at a point that appears to be a call to an rstan function, but no error message is ever output. The only reason I know the function fails is that nothing gets assigned to lpres, and expected console output is never produced.
On another occasion an rstan call caused R itself to outright crash.
I've encountered these problems with both rstan 2.5 and rstan 2.6, and on two different machines.
I will add more information as I continue investigating this.
Copied from original issue: stan-dev/stan#1400