STAN 模型块中不存在变量 "cholesky_factor_cov"

Variable "cholesky_factor_cov" does not exist in STAN model block

我正在尝试从边缘化高斯混合模型的后验分布进行模拟。这是我的代码:


data {
  int<lower=0> d;
  int<lower=0> n;         
  int<lower=0> k;
  row_vector[d] y[n];
  vector[d] mu0;
  cov_matrix[d] sig0;
  real<lower=0> alpha;
}
parameters {
  vector[d] mu[k];
  cov_matrix[d] sig[k];
  // simplex[k] pi;
}


model {
   cholesky_factor_cov[d] chol_sig[k];
  for(i in 1:k)
    chol_sig[i]=cholesky_decompose(sig[i]);

  vector[k] lps;

  for( i in 1:k){
    target+= multi_normal_cholesky_lpdf(mu[i] | mu0, chol_sig[i]);
    target+= inv_wishart_lpdf(sig[i] | d+10, sig0);
  }


  for (i in 1:n) {
    // lps = log_thet;
    for (j in 1:k)
      lps[j] = multi_normal_cholesky_lpdf(y[i] | mu[j], chol_sig[j]);
    target += log_sum_exp(lps);
  }
}

它抛出以下错误:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Variable "cholesky_factor_cov" does not exist.
 error in 'model728c4ff59f3c_mixture' at line 34, column 22
  -------------------------------------------------
    32: // }
    33: model {
    34:    cholesky_factor_cov[d] chol_sig[k];
                             ^
    35:   for(i in 1:k)
  -------------------------------------------------

Error in stanc(file = file, model_code = model_code, model_name = model_name,  :
  failed to parse Stan model 'mixture' due to the above error.

我不能在 STAN 模型中声明类型为 ``cholesky_factor_cov" 的变量吗?请帮忙。

您不能在 Stan 程序的 model 块内声明矩阵或向量的特化,因为不检查它们的有效性。但是您可以将其声明为方阵数组,例如

model {
  matrix[d,d] chol_sig[k];
  ...