我在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中做到?

这是我得到的错误并回溯:

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>

最佳答案

您要查找的功能是increment_log_prob(...)

有关详细信息,请查阅Stan手册:http://mc-stan.org/manual.html

还值得注意的是,获得Stan帮助的最佳位置是当前stan-users邮件列表:http://mc-stan.org/groups.html

关于python - 在Stan模型中将概率乘以常数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30711689/

10-12 23:25