我在PySTAN工作。假设我的可能性是:p1 * p2
其中p1 ~ N(x, xerr)
和
p2 = 0.823 if t = 0
1 if t = 1
我的模特是:
model = """
data {
int<lower=0> N; // number of points
vector[N] x;
vector[N] xerr;
vector[N] cnd; // indicator: elements are 0 or 1
}
parameters {
real alpha; // intercept
real beta; // slope
}
model {
vector[N] p2;
// PRIORS
alpha ~ normal(0,10);
beta ~ normal(0,10);
p1 ~ normal(x, xerr);
for (i in 1:N) {
if (cnd[i] == 1)
p2[i] ~ 0.823;
else if (cnd[i] == 0)
p2[i] ~ 1;
}
}
"""
但是,我收到了错误!
我所要做的就是在满足特定条件的情况下将可能性乘以常数。我怎么能在PySTAN中做到这一点?
这是我得到的错误&amp;回溯:
Traceback (most recent call last):
File "/home/paula/Desktop/fakedata.py", line 91, in <module>
fit = pystan.stan(model_code=fit_code, data=fit_data, iter=10, chains=1)
File "/usr/local/lib/python2.7/dist-packages/pystan/api.py", line 373, in stan
save_dso=save_dso, verbose=verbose)
File "/usr/local/lib/python2.7/dist-packages/pystan/model.py", line 219, in __init__
obfuscate_model_name=obfuscate_model_name)
File "/usr/local/lib/python2.7/dist-packages/pystan/api.py", line 129, in stanc
raise ValueError(error_msg)
ValueError: Failed to parse Stan model 'anon_model_04ef08903b48c28a7c3fee52b890cdaf'. Error message:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
ERROR at line 43
41: for (i in 1:N) {
42: if (cnd[i] == 1)
43: p2[i] ~ 0.823
^
44: else if (cnd[i] == 0)
PARSER EXPECTED: <distribution and parameters>
答案 0 :(得分:1)
您正在寻找的功能是increment_log_prob(...)
。
查看Stan手册了解详情:http://mc-stan.org/manual.html
值得注意的是,获得Stan帮助的最佳位置目前是stan-users
邮件列表:http://mc-stan.org/groups.html