我正在尝试在 python、pymc3 和 matplotlib 中绘制多开关点后验分布,但是图形输出看起来与后验分布不同,谁能告诉我我做错了什么,好吗?
我的情节代码如下
early_rate_samples = trace[‘lambda_1’]
late_rate_samples = trace[‘lambda_2’]
later_rate_samples = trace[‘lambda_3’]
changepoint_samples = trace[‘tau_1’]
changepoint_2_samples = trace[‘tau_2’]
#N samples from the corresponding posterior distribution.
N = ((changepoint_samples.shape[0]) + (changepoint_2_samples.shape[0]))
expected_Outbreaks_per_week = np.zeros(number_of_weeks)
for week in range(0, number_of_weeks):
# ix is a bool index of all changepoint samples corresponding to
# the changepoint occurring prior to value of ‘week’
ix = (week <= changepoint_samples) & (changepoint_2_samples >= week)
expected_Outbreaks_per_week[week] = (early_rate_samples[ix].sum() + late_rate_samples[ix].sum() + later_rate_samples[~ix].sum()) / N
plt.plot(range(number_of_weeks), expected_Outbreaks_per_week, lw=4, color="#E24A33",
label=“expected number of Outbreak incident”)
plt.xlim(0, number_of_weeks)
plt.xlabel(“Time (weeks)”)
plt.ylabel(“Expected # Outbreaks”)
plt.title(“Expected number of Outbreak Incident”)
plt.ylim(0, 15)
plt.bar(np.arange(len(twitter_df[‘twitter_stream_count’])), twitter_df[‘twitter_stream_count’], color="#348ABD", alpha=0.65,
label=“observed Outbreak per week”)
plt.legend(loc=“upper left”);
总结结果
阴谋
该图看起来与后验分布相差甚远,谁能告诉我我在这里做错了什么?