Beispiel #1
0
def test_logp_scaling(df):
    engine = Engine(df)
    engine.init_models(8)
    engine.run(500)

    x = np.linspace(3, 7, 200)

    p_true = norm.pdf(x, loc=5., scale=.5)
    lp_baxcat = engine.probability(x[:, np.newaxis], ['t'],
                                   given=[('x', 1), ('y', 2)])

    inftest_plot(x, p_true, np.exp(lp_baxcat), 'p_t-xy', RESDIR)

    assert abs(max(p_true) - max(np.exp(lp_baxcat))) < .05
def test_logp_scaling(df):
    engine = Engine(df)
    engine.init_models(8)
    engine.run(500)

    x = np.linspace(3, 7, 200)

    p_true = norm.pdf(x, loc=5., scale=.5)
    lp_baxcat = engine.probability(x[:, np.newaxis], ['t'],
                                   given=[('x', 1), ('y', 2)])

    inftest_plot(x, p_true, np.exp(lp_baxcat), 'p_t-xy', RESDIR)

    assert abs(max(p_true) - max(np.exp(lp_baxcat))) < .05
Beispiel #3
0
def test_likelihood(n_rows, n_cols, n_cats, cat_sep, n_models, n_iter):
    dg, engine = gen_data_and_engine(n_rows, n_cols, n_cats, cat_sep, n_models,
                                     n_iter)
    cols = list(range(n_cols))

    ttl_base = "NNG_LK-r%d-c%d-k%d-s%1.2f-m%d-i%d_" \
        % (n_rows, n_cols, n_cats, cat_sep, n_models, n_iter,)

    for col in cols:
        xmin = dg.df[col].min()
        xmax = dg.df[col].max()
        x = np.linspace(xmin, xmax, 200)

        l_dg = dg.log_likelihood(x, col)
        l_eng = engine.probability(x[:, np.newaxis], [col])

        r, _ = pearsonr(l_dg, l_eng)
        inftest_plot(x, l_dg, l_eng, ttl_base + 'COL-%d' % col, RESDIR)

        assert abs(r - 1) < .05
def test_likelihood(n_rows, n_cols, n_cats, cat_sep, n_models, n_iter):
    dg, engine = gen_data_and_engine(n_rows, n_cols, n_cats, cat_sep, n_models,
                                     n_iter)
    cols = list(range(n_cols))

    ttl_base = "NNG_LK-r%d-c%d-k%d-s%1.2f-m%d-i%d_" \
        % (n_rows, n_cols, n_cats, cat_sep, n_models, n_iter,)

    for col in cols:
        xmin = dg.df[col].min()
        xmax = dg.df[col].max()
        x = np.linspace(xmin, xmax, 200)

        l_dg = dg.log_likelihood(x, col)
        l_eng = engine.probability(x[:, np.newaxis], [col])

        r, _ = pearsonr(l_dg, l_eng)
        inftest_plot(x, l_dg, l_eng, ttl_base + 'COL-%d' % col, RESDIR)

        assert abs(r-1) < .05