pymc的安装还是pymc3?
(Installation — PyMC 5.17.0 documentation)安装最新版本的pymc
(注意,现在pymc3
已更名为pymc
)。
Name: numpy
Version: 1.22.1
Name: pymc
Version: 5.6.1
Name: Theano
Version: 1.0.5
Name: Theano-PyMC
Version: 1.1.2
import numpy as np import pymc as pm import arviz as az import matplotlib.pyplot as pltif __name__ == '__main__':np.random.seed(42)true_mean = 5true_std = 2data = np.random.normal(true_mean, true_std, size=100)with pm.Model() as model:mean = pm.Normal('mean', mu=0, sigma=10)std = pm.HalfNormal('std', sigma=5)obs = pm.Normal('obs', mu=mean, sigma=std, observed=data)with model:trace = pm.sample(200, tune=100)az.plot_trace(trace)plt.show()