gpt4 book ai didi

python - pystan .plot() 两次绘制跟踪摘要

转载 作者:太空宇宙 更新时间:2023-11-04 00:49:38 24 4
gpt4 key购买 nike

这可能是一个愚蠢的问题,但每当我使用 .plot() 函数时,它都会绘制两次摘要。任何人都知道,为什么这样做以及我如何才能阻止它? pystan.plot()

如您所见,如果需要的话,我正在使用 jupyter 笔记本。

任何 stan 模型(以及两个单独的安装)都会发生这种情况

这段代码会为我带来问题

import pystan 
import numpy as np
model_string = """
data {
int<lower=0> N;
int y[N];
}
parameters {
real<lower=0, upper=1> theta;
}
model {
theta ~ beta(1,1);
y ~ bernoulli(theta);
}
"""
N = 50
z = 10
y = np.append(np.repeat(1, z), np.repeat(0, N - z))
dat = {'y':y,
'N':N}

fit = pystan.stan(model_code=model_string, data=dat, iter=1000, warmup=200, thin=1, chains = 3)
fit.plot()

最佳答案

这是由 %matplotlib inline 语句绘制的比您想要的多引起的。 StanFit4Model.plot 方法调用 matplotlib.pyplot.subplot,当您的笔记本有 %matplotlib inline 时,该调用本身将绘制一个图。然后该方法返回 Figure 对象。如果您不捕获它,您的笔记本会决定将其作为图像显示给您而不是打印出来,您会得到双图。

您可以通过捕获输出 Figure 来输出单个图。从

更改您的代码
fit.plot()

成为

fig = fit.plot()

关于python - pystan .plot() 两次绘制跟踪摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37646860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com