Ejemplo n.º 1
0
def test_marg():
    spn = example_spns.get_gender_spn()

    spn1 = fn.marg(spn, [2])
    fn.plot_spn(spn1, "marg1.pdf")

    spn2 = fn.marg(spn, [0])
    fn.plot_spn(spn2, "marg2.pdf")

    spn3 = fn.marg(spn, [1])
    fn.plot_spn(spn3, "marg3.pdf")

    spn4 = fn.marg(spn, [1, 2])
    fn.plot_spn(spn4, "marg4.pdf")

    rang = [None, NominalRange([1]), None]
    prob, spn5 = fn.marg_rang(spn, rang)
    fn.plot_spn(spn5, "marg5.pdf")

    rang = [None, NominalRange([1]), NumericRange([[10, 12]])]
    prob, spn6 = fn.marg_rang(spn, rang)
    fn.plot_spn(spn6, "marg6.pdf")

    rang = [NominalRange([0]), NominalRange([1]), None]
    prob = fn.prob(spn, rang)
    print(prob)
    prob = fn.prob(spn6, rang)
    print(prob)
Ejemplo n.º 2
0
def test_sampling():
    spn = example_spns.get_gender_spn()
    '''
    Always same random number generator
    '''

    samples = fn.sampling(spn, n_samples=10, random_seed=1)
    print(samples)

    samples = fn.sampling_rang(spn,
                               rang=[None, None, None, None],
                               n_samples=10,
                               random_seed=1)
    print(samples)

    samples = fn.sampling_rang(
        spn,
        rang=[None, None, NumericRange([[10, 11], [29, 30]])],
        n_samples=10,
        random_seed=1)
    print(samples)

    samples = fn.sampling_rang(
        spn,
        rang=[NominalRange([0]), None,
              NumericRange([[14, 15], [29, 30]])],
        n_samples=10,
        random_seed=1)
    print(samples)
Ejemplo n.º 3
0
def test_expect():
    spn = example_spns.get_gender_spn()

    rang = [None, None, None]
    expect = fn.expect(spn, feature_id=2, rang=rang)
    print(expect)

    rang = [NominalRange([0]), None, None]
    expect = fn.expect(spn, feature_id=2, rang=rang)
    print(expect)

    rang = [NominalRange([1]), None, None]
    expect = fn.expect(spn, feature_id=2, rang=rang)
    print(expect)

    rang = [None, NominalRange([0]), None]
    expect = fn.expect(spn, feature_id=2, rang=rang)
    print(expect)

    feature_scope = {2}
    data = np.array([[np.nan, np.nan, np.nan]])
    expect = fn.expects_spnflow(spn, feature_scope, data)
    print(expect)

    feature_scope = {2}
    data = np.array([np.nan, np.nan, np.nan])
    expect = fn.expect_spnflow(spn, feature_scope, data)
    print(expect)
Ejemplo n.º 4
0
def test_prob():
    spn = example_spns.get_gender_spn()

    rang = [None, None, None]
    prob = fn.prob(spn, rang)
    print(prob)

    rang = [NominalRange([0]), NominalRange([1]), NumericRange([[20]])]
    prob = fn.prob(spn, rang)
    print(prob)

    ranges = np.array([[None, None, NumericRange([[0, 20]])],
                       [NominalRange([0]), None, None],
                       [None, NominalRange([1]), None]])
    probs = fn.probs(spn, ranges)
    print(probs)

    inst = [0, np.nan, np.nan]
    prob = fn.prob_spflow(spn, inst)
    print(prob)

    data = np.array([[0, np.nan, np.nan], [0, 1, np.nan]])
    probs = fn.probs_spflow(spn, data)
    print(probs)
Ejemplo n.º 5
0
        for interval in zip(val_space[1:], val_space[:-1]):
            conds.append(NumericRange([list(interval)]))
            labels.append(str(list(interval)))
    else:
        raise Exception(
            "Not implemented for other than discrete or numeric ...: " +
            str(value_dict[target_id][0]))
    return conds, labels


if __name__ == '__main__':

    from simple_spn.example import example_spns
    from util import io

    spn = example_spns.get_gender_spn()

    loc = "_spns"
    ident = "rdc=" + str(0.3) + "_mis=" + str(0.1)
    spn, value_dict, _ = io.load(ident, "titanic", loc)
    spn = fn.marg(spn, keep=[0, 1, 2, 3, 6])

    #visualize_sub_populations(spn)
    #visualize_overall_distribution(spn, value_dict=value_dict, save_path="overall_visualization.pdf")
    #visualize_target_based_overall_distribution_single(spn, 0, value_dict=value_dict, save_path="overall_visualization_target_based.pdf")
    #visualize_target_based_overall_distribution_compact(spn, 0, value_dict=value_dict, save_path="overall_visualization_target_based_compact.pdf")
    visualize_expected_sub_populations(spn,
                                       value_dict=value_dict,
                                       save_path="expectation_line_plot.pdf")
    visualized_target_based_expected_sub_populations(
        spn,
Ejemplo n.º 6
0
def test_plot():
    spn = example_spns.get_gender_spn()
    fn.plot_spn(spn, "sample_spn.pdf")

    spn = example_spns.get_credit_spn()()
    fn.plot_spn(spn, "sample_spn2.pdf")
Ejemplo n.º 7
0
def test_get_overall_population():
    spn = example_spns.get_gender_spn()
    overall_pop = fn.get_overall_population(spn)

    print(overall_pop)
Ejemplo n.º 8
0
def test_generate_value_dict():
    spn = example_spns.get_gender_spn()
    val_dict = fn.generate_adhoc_value_dict(spn)

    print(val_dict)
Ejemplo n.º 9
0
def test_get_subpopulations():
    spn = example_spns.get_gender_spn()
    #rang = [NominalRange([0]), NominalRange([1]), None]
    sub_pops = fn.get_sub_populations(spn)

    print(sub_pops)