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)
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")
df = pd.DataFrame(data, columns=[value_dict[i][1] for i in range(num_vars)]) print(df.corr()) # parameters for the construction rdc_threshold = 0.1 min_instances_slice = 0.1 if not spn_handler.exist_spn(dataset_name, rdc_threshold, min_instances_slice): print("Creating SPN ...") # get data # df, value_dict, parametric_types = real_data.get_titanic() spn, value_dict, _ = spn_handler.create_parametric_spns( data, data_types, dataset_name, [rdc_threshold], [min_instances_slice], value_dict, save=False) # # Load SPN # spn, value_dict, _ = spn_handler.load_spn(dataset_name, rdc_threshold, min_instances_slice) # Print some statistics fn.print_statistics(spn) visualize_expected_sub_populations(spn, value_dict, 10) visualize_sub_populations(spn, value_dict, 10) subpops = fn.get_sub_populations(spn, ) print(subpops) print('============') pprint(subpops) fn.plot_spn(spn, "icecream_spn.pdf", value_dict)
bbox_inches='tight', dpi=400) plt.show() from spn.structure.leaves.parametric.Parametric import Poisson # Z plot fig, ax = plt.subplots(figsize=(size[0] / 2.5, size[1])) currp = p[4] ticks = list(range(len(currp))) labels = ['{}{}'.format('Z', i) for i, _ in enumerate(currp)] ax.bar( ticks, currp, ) ax.set_xticks(ticks, ) ax.set_xticklabels(labels) ax.set_ylim([0., 1.05]) ax.set_ylabel('probability') ax.yaxis.set_label_position("right") ax.yaxis.tick_right() plt.savefig('../../_figures/rule_extraction/leaf5.png', bbox_inches='tight', dpi=400) plt.show() fn.plot_spn(spn) df, _, _ = get_titanic_bins() c = df.Pclass.astype(int).value_counts() r = c / c.sum() r.index = pd.Index(['1st Class', '2nd Class', '3rd Class']) r.plot('bar') pass
df = df[["Survived", "Sex", "Age", "Fare", "Pclass"]] df, val_dict, param_types = fn.transform_dataset(df) #print data after transformation (top 5 rows) io.print_pretty_table(df.head(5)) '''' SPN functions ''' #Load synthetic example SPN (very simple SPN) from simple_spn.example import example_spns spn = example_spns.get_gender_spn() #plot spn fn.plot_spn(spn, "sample_spn.pdf", value_dict) #generate samples 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,