예제 #1
0
def check_dpm(impl, data_count, beta0):
    check_cm(impl)
    data = histogram(np.random.randint(50, size=data_count))
    data = dict([(str(i), obs) for i, obs in enumerate(data)])
    betas = dict([(str(i), (1 - beta0) / len(data))
        for i, obs in enumerate(data)])
    hp = {
            'gamma': 1.,
            'alpha': 1.,
            'beta0': beta0,
            'betas': betas
         }
    ss = {'counts': data}
    cm = ComponentModel(
            impl,
            ss=ss,
            hp=hp)
    samples = cm.sample_data(SAMPS)
    counts = list(histogram([y for y in samples if y != -1]))
    probs = list(np.exp([cm.pred_prob(x) for x in range(max(samples) + 1)]))
    counts.append(len([y for y in samples if y == -1]))
    probs.append(np.exp(cm.pred_prob(-1)))
    assert_less(1 - sum(probs), THRESH)
    probs, counts = zip(*sorted(zip(probs, counts), reverse=True)[:TOPN])
    p = mgof(probs, counts, SAMPS, truncated=True)
    assert_greater(p, THRESH)
예제 #2
0
def _check_discrete(cm):
    samples = cm.sample_data(SAMPS)
    counts = histogram(samples)
    probs = np.exp([cm.pred_prob(x) for x in range(max(samples) + 1)])
    assert_less(1 - sum(probs), THRESH)
    probs, counts = zip(*sorted(zip(probs, counts), reverse=True)[:TOPN])
    p = mgof(probs, counts, SAMPS, truncated=True)
    assert_greater(p, THRESH)
예제 #3
0
def _check_discrete(cm):
    samples = cm.sample_data(SAMPS)
    counts = histogram(samples)
    probs = np.exp([cm.pred_prob(x) for x in range(max(samples) + 1)])
    assert_less(1 - sum(probs), THRESH)
    probs, counts = zip(*sorted(zip(probs, counts), reverse=True)[:TOPN])
    p = mgof(probs, counts, SAMPS, truncated=True)
    assert_greater(p, THRESH)
예제 #4
0
def check_dd(impl, data_count, D):
    check_cm(impl)
    data = histogram(np.random.randint(D, size=data_count), bin_count=D)
    cm = ComponentModel(
            impl,
            ss={'counts': data},
            p={'D': D})
    cm.realize_hp()
    _check_discrete(cm)
예제 #5
0
def check_dpm(impl, data_count, beta0):
    check_cm(impl)
    data = histogram(np.random.randint(50, size=data_count))
    data = dict([(str(i), obs) for i, obs in enumerate(data)])
    betas = dict([(str(i), (1 - beta0) / len(data))
                  for i, obs in enumerate(data)])
    hp = {'gamma': 1., 'alpha': 1., 'beta0': beta0, 'betas': betas}
    ss = {'counts': data}
    cm = ComponentModel(impl, ss=ss, hp=hp)
    samples = cm.sample_data(SAMPS)
    counts = list(histogram([y for y in samples if y != -1]))
    probs = list(np.exp([cm.pred_prob(x) for x in range(max(samples) + 1)]))
    counts.append(len([y for y in samples if y == -1]))
    probs.append(np.exp(cm.pred_prob(-1)))
    assert_less(1 - sum(probs), THRESH)
    probs, counts = zip(*sorted(zip(probs, counts), reverse=True)[:TOPN])
    p = mgof(probs, counts, SAMPS, truncated=True)
    assert_greater(p, THRESH)
예제 #6
0
def check_dd(impl, data_count, D):
    check_cm(impl)
    data = histogram(np.random.randint(D, size=data_count), bin_count=D)
    cm = ComponentModel(impl, ss={'counts': data}, p={'D': D})
    cm.realize_hp()
    _check_discrete(cm)