test_normal_categorical.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:cgpm 作者: probcomp 项目源码 文件源码
def test_conditional_real(state):
    # Simulate from the conditional Z|X
    fig, axes = plt.subplots(2,3)
    fig.suptitle('Conditional Simulation Of Indicator Z Given Data X')
    # Compute representative data sample for each indicator.
    means = [np.mean(DATA[DATA[:,1]==t], axis=0)[0] for t in INDICATORS]
    for mean, indicator, ax in zip(means, INDICATORS, axes.ravel('F')):
        samples_subpop = [s[1] for s in
            state.simulate(-1, [1], {0:mean}, None, N_SAMPLES)]
        ax.hist(samples_subpop, color='g', alpha=.4)
        ax.set_title('True Indicator %d' % indicator)
        ax.set_xlabel('Simulated Indicator')
        ax.set_xticks(INDICATORS)
        ax.set_ylabel('Frequency')
        ax.set_ylim([0, ax.get_ylim()[1]+10])
        ax.grid()
        # Check that the simulated indicator agrees with true indicator.
        true_ind_a = indicator
        true_ind_b = indicator-1  if indicator % 2 else indicator+1
        counts = np.bincount(samples_subpop)
        frac = sum(counts[[true_ind_a, true_ind_b]])/float(sum(counts))
        assert .8 < frac
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号