fake_data_generator.py 文件源码

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

项目:partycrasher 作者: naturalness 项目源码 文件源码
def test_chinese_restaurant_process(self):
        print(sys.path)
        from matplotlib import pyplot
        import matplotlib
        from scipy import stats
        alpha = 20
        test_size = 1000
        tests = 1000
        data = [0]
        for j in range(0, tests):
            cr = ChineseRestaurant(alpha, Numbers())
            for i in range(0, test_size):
                new_sample = cr.draw()
                if new_sample >= len(data):
                    data.append(0)
                data[new_sample] += 1
            assert cr.heap[1] == test_size
        pyplot.switch_backend('Qt5Agg')
        #data=sorted(data, reverse=True)
        print(len(data))
        actual_plot, = pyplot.plot(range(1,len(data)), data[1:], label='actual avg')
        expected = [0]
        remain = test_size * tests
        for i in range(1, len(data)):
            break_ = stats.beta.mean(1.0, float(alpha)) * remain
            expected.append(break_)
            remain -= break_
        #print est
        expected_plot, = pyplot.plot(range(1,len(data)), expected[1:], 'r', linewidth=1, label='expected')
        matplotlib.interactive(True)
        pyplot.ylabel("People at Table")
        pyplot.xlabel("Table Number")
        pyplot.title("Chinese Restaurant Process Unit Test")
        pyplot.legend()
        pyplot.show(block=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号