RStan - stan_file 模型代码中的问题 - 变分贝叶斯

时间:2021-07-13 23:44:47

标签: r bayesian stan rstan hierarchical-bayesian

我正在尝试进行变分推理,以便获得关于目标分布的最佳近似分布:正态-逆-Wishart。

Normal-Inverse-Wishart distribution

然而,当我用模型代码编译 stan 文件时,它给出了错误:

<块引用>

stanc 中的错误(文件 = 文件,模型代码 = 模型代码,模型名称 = ?>模型名称,:0 'string' 中的语法错误,第 16 行,第 14 列到第 15 列,解析 > 错误: 模型结束后的预期“生成数量{”或文件结束>块。

我试图调查这是指什么,但我需要一些帮助。我的 R 代码是:

stan_file <- "RStan VI model.stan"
stan_model <- rstan::stan_model(file = stan_file) // Error occurs at this line

RStan 文件模型代码为:

data {
  int<lower=1> N; // number of assets
  real<lower=0> nu0; // prior confidence for sigma
  matrix[N, N] sigma_0; // prior sigma
  real<lower=0> T0; // prior confidence for mu
  vector[N] mu0; // prior mu
}
parameters {
  matrix[N, N] sigma;
  vector[N] mu; 
}
transformed parameters {
  matrix[N, N] a;
  matrix[N, N] b;
  a = sigma0*nu0;
  b = sigma/T0;
}
model {
  target += inv_wishart_lpdf(sigma | nu0, a);
  target += normal_lpdf(mu | mu0, b);
}

我什至尝试将模型代码的最后一部分更改为:

model {
  sigma ~ inv_wishart(nu0, a);
  mu ~ normal(mu0, b);
}

但还是同样的错误。有谁知道错误是什么以及我如何解决它?

非常感谢。

最好的, 尼哈尔

0 个答案:

没有答案