故障排除Rstan错误“运行命令...状态为1”

时间:2014-03-12 15:11:36

标签: c++ r gcc

我收到一个我不明白的Rstan错误,并且此特定错误在之前的Stack Overflow问题中未得到解决。

调用Rstan的R代码是

    # Fit the model
    start = Sys.time()
    pvl_d_fit <- stan(file = 'pvl_d.stan', data = pvl_d_dat, 
              verbose = TRUE,
              warmup = 1000, iter = 4000, thin = 3, chains = 3, 
              init = 'random', pars = c(  
              "A_ind", "mu_A", "la_A",
              "w_ind", "mu_w", "la_w",
              "a_ind", "mu_a", "la_a",
              "c_ind", "mu_c", "la_c"))
    end = Sys.time()                  
    end - start 

获得以下输出:

SAMPLING FOR MODEL 'pvl_d' NOW (CHAIN 1).

Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
Error in function stan::prob::normal_log(N4stan5agrad3varE): Random variable is -1.#IND:0, but must not be nan!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

之前有人碰到过吗?

(注意:这条消息一遍又一遍地重复)。

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/User/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/User/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: file9d8452242a.o: too many sections (39807)
C:\Users\User\AppData\Local\Temp\ccOl2E
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file9d8452242a.cpp 2> file9d8452242a.cpp.err.txt' had status 1 

stan文件是:

    data {
      int<lower=1> n_s;                       // # subjects
      int<lower=1> n_t;                       // # trials
      int<lower=0,upper=4> choice[n_s, n_t];  // # subj. x # trials matrix with choices
      real<lower=-25,upper=2> net[n_s, n_t];  // Net amount of wins + losses   
                                              // (# subj. x # trials matrix) 
    }

    parameters {
      // Group-level mean parameters
      real mu_A_pr;   
      real mu_w_pr;
      real mu_a_pr;  
      real mu_c_pr;

      // Group-level standard deviation  
      real<lower=0> sd_A;
      real<lower=0> sd_w;
      real<lower=0> sd_a;
      real<lower=0> sd_c;    

      // Individual-level paramters    
      real A_ind_pr[n_s]; 
      real w_ind_pr[n_s]; 
      real a_ind_pr[n_s];   
      real c_ind_pr[n_s]; 
    }

    transformed parameters {
      real<lower=0,upper=1> mu_A;   
      real<lower=0,upper=5> mu_w;
      real<lower=0,upper=1> mu_a;  
      real<lower=0,upper=5> mu_c;

      // Individual-level paramters    
      real<lower=0,upper=1> A_ind[n_s]; 
      real<lower=0,upper=5> w_ind[n_s]; 
      real<lower=0,upper=1> a_ind[n_s];   
      real<lower=0,upper=5> c_ind[n_s];   

      // Group-level precision parameters  
      real<lower=0> la_A;
      real<lower=0> la_w;
      real<lower=0> la_a;
      real<lower=0> la_c;     

      mu_A <- Phi(mu_A_pr);
      mu_w <- Phi(mu_w_pr) * 5;
      mu_a <- Phi(mu_a_pr); 
      mu_c <- Phi(mu_c_pr) * 5;  

      for (s in 1:n_s)
      {
         A_ind[s] <- Phi(A_ind_pr[s]);
         w_ind[s] <- Phi(w_ind_pr[s]) * 5;
         a_ind[s] <- Phi(a_ind_pr[s]); 
         c_ind[s] <- Phi(c_ind_pr[s]) * 5;  
      }

       la_A <- pow(sd_A, -2);
       la_w <- pow(sd_w, -2);
       la_a <- pow(sd_a, -2);
       la_c <- pow(sd_c, -2);  
     }

     model {
      vector[4] p;
      real Ev[4];
      real dummy[4];
      real theta;
      real v;

      # Prior on the group-level mean parameters
      # probit scale [-Inf, Inf]  
      mu_A_pr ~ normal(0, 1);
      mu_w_pr ~ normal(0, 1);
      mu_a_pr ~ normal(0, 1);
      mu_c_pr ~ normal(0, 1);

       # Prior on the group-level standard deviation
      sd_A ~ uniform(0,1.5); 
      sd_w ~ uniform(0,1.5); 
      sd_a ~ uniform(0,1.5);    
      sd_c ~ uniform(0,1.5);

       # Individual-level paramters
       for (s in 1:n_s)
      {
        A_ind_pr[s] ~ normal(mu_A_pr, sd_A);      
        w_ind_pr[s] ~ normal(mu_w_pr, sd_w);   
        a_ind_pr[s] ~ normal(mu_a_pr, sd_a);   
        c_ind_pr[s] ~ normal(mu_c_pr, sd_c);    
      }

      for (s in 1 : n_s)  // loop over subjects
      {  
        theta <- pow(3, c_ind[s]) - 1;     

       // Trial 1
        for (d in 1 : 4)  // loop over decks
        {  
          p[d] <- .25;
          Ev[d] <- 0;
        }  
        choice[s,1] ~ categorical(p);

        // Remaining trials
        for (t in 1 : (n_t - 1))  
            { 
            if (net[s,t] >= 0)
            v <- pow(net[s,t], A_ind[s]);
            else
            v <- -1 * w_ind[s] * pow(abs(net[s,t]), A_ind[s]);

          Ev[choice[s,t]] <- (1 - a_ind[s]) * Ev[choice[s,t]] + a_ind[s] * v;      

          for (d in 1 : 4)  // loop over decks
          dummy[d] <- exp(fmax(fmin(Ev[d] * theta, 450), -450));       

          for (d in 1 : 4)  // loop over decks
          p[d] <- dummy[d] / sum(dummy); 

          choice[s, t + 1] ~ categorical(p);
        }
      } 
    }

1 个答案:

答案 0 :(得分:0)

“信息性消息”可能是Stan邮件列表中最常(未)回答的问题。

  • 这可能意味着您的模型定义不明确;要确定这是否是问题,请先尝试使用非常狭窄的先验,直到消息消失或很少见。在那之后,一个接一个地将先辈释放到野外,找到不明确的罪魁祸首。
  • 然而,在大多数情况下,消息来自错误定义的初始值;这些消息经常在老化之后消失(对不起,安德鲁,应该是热身)阶段。如果结果在合理的范围内,可能使用较窄的先验获得,请先尝试使用这些作为初始值,然后添加小的随机变量。
  • 有时候,完全删除初始值并让stan参与肮脏的工作会有所帮助;但可能你已经尝试过了。

这就是说,我对你的“编译”错误意味着什么感到困惑。该模型不应该与该错误一起运行。