<jupyter_start><jupyter_text>Experiment I: Relative confidence small to full Compare the evolution of the confidence function for the small and the full graphs<jupyter_code>%load_ext autoreload
%autoreload 2<jupyter_output>The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>Prepare graphs<jupyter_code>from hypotest.ontologies import molecular_subgraph, full_graph
from grontocrawler.graph import produce_graph
from hypotest.graph_mutation import normalize_hypothgraph
sub_onto = molecular_subgraph.g
full_onto = full_graph.g
sub_unnorm = produce_graph.produce_graph(sub_onto, options=['existential-arcs'])
full_unnorm = produce_graph.produce_graph(full_onto, options=['existential-arcs'])
sub_norm, _ = normalize_hypothgraph.normalize_hypothgraph(sub_unnorm)
full_norm, _ = normalize_hypothgraph.normalize_hypothgraph(full_unnorm)
set(sub_norm.nodes()).issubset(set(full_norm.nodes()))
set(sub_norm.edges()).issubset(set(full_norm.edges()))<jupyter_output><empty_output><jupyter_text>Statistics of graphs Number of nodes and arcs<jupyter_code>print('Subgraph: number of nodes {} and arcs {}'.format(len(sub_norm.nodes()), len(sub_norm.edges())))
print('Fullgraph: number of nodes {} and arcs {}'.format(len(full_norm.nodes()), len(full_norm.edges())))<jupyter_output>Fullgraph: number of nodes 30 and arcs 57<jupyter_text>Choose configuration<jupyter_code>from hypotest.graph_generation import hypoth_conf
Hypoth_Conf = hypoth_conf.Hypoth_Conf
conf_source, conf_target = hypoth_conf.generate_max_endpoints(sub_norm)
print(conf_source, conf_target)<jupyter_output>('http://plumdeq.xyz/ontologies/hypothesis/Synovial_inflammation', 'http://plumdeq.xyz/ontologies/hypothesis/Cartilage_degeneration')<jupyter_text>Statistics on the configuration Number of paths<jupyter_code>import networkx as nx
nb_sub = len(list(nx.all_simple_paths(sub_norm, conf_source, conf_target)))
print('Number of paths in the subgraph is {}'.format(nb_sub))
nb_full = len(list(nx.all_simple_paths(full_norm, conf_source, conf_target)))
print('Number of paths in the full graph is {}'.format(nb_full))
conf = Hypoth_Conf(conf_source, conf_target, [])
from hypotest.graph_generation import boundary
nb_sub_interior = len(list(boundary.in_boundary_interior(sub_norm, conf_source, conf_target)))
print('Number of nodes in the interior of the subgraph is {}'.format(nb_sub_interior))
nb_full_interior = len(list(boundary.in_boundary_interior(full_norm, conf_source, conf_target)))
print('Number of nodes in the interior of the full graph is {}'.format(nb_full_interior))<jupyter_output>Number of nodes in the interior of the full graph is 12<jupyter_text>Draw this configuration<jupyter_code>import os, sys
path_to_images = '../images/results-paper/exp1-rel-conf/'
relative_graphs = os.path.abspath(os.path.join(path_to_images, 'relative-graphs.dot'))
relative_graphs
from hypotest.io import write_dot
with open(relative_graphs, 'w') as f:
    write_dot.big_small_to_dot(full_norm, sub_norm, conf, f)
relative_graphs_png = os.path.abspath(os.path.join(path_to_images, 'relative-graphs.png'))
relative_graphs_png
!dot -Tpng -o $relative_graphs_png $relative_graphs
from IPython.display import Image
Image(relative_graphs_png)<jupyter_output><empty_output><jupyter_text>Compute confidences We assume trivial weighting scheme for the factors<jupyter_code>from hypotest.stats import confidences
sub_unnormalized_confidences = confidences.confidence_spectrum(sub_norm, conf_source, conf_target, normalized=False)
sub_normalized_confidences = confidences.confidence_spectrum(sub_norm, conf_source, conf_target, normalized=True)
full_unnormalized_confidences = confidences.confidence_spectrum(full_norm, conf_source, conf_target, normalized=False)
full_normalized_confidences = confidences.confidence_spectrum(full_norm, conf_source, conf_target, normalized=True)
max_full = max(full_unnormalized_conidences)
max_full
sub_norm_to_full_confidences = [np.array(x)/max_full for x in sub_unnormalized_confidences]<jupyter_output><empty_output><jupyter_text>Plot confidences<jupyter_code>%pylab inline
from matplotlib import pyplot as plt<jupyter_output><empty_output><jupyter_text>Path for the figure, so that we can save in SVG or any other format<jupyter_code># When we plot confidences we need to take into account 'bigger' and 
# 'smaller' 
# graphs, i.e., the sizes of the confidence vectors might not be the same
def plot_confidences(bigger, smaller, bigger_label=None, 
                     smaller_label=None, 
                     legend_loc='upper left',
                     xlabel="",
                     ylabel=""):
    # Determine xs
    x_s = range(len(smaller))
    x_b = range(len(bigger))
    
    min_x = min(x_b)
    max_x = max(x_b)
    # min max of ys, they are list of lists
    min_y = np.min(bigger)[0]
    max_y = np.max(bigger)[0]
    
    # figure where you draw everything
    fig, ax = plt.subplots(nrows=1, ncols=1)
    
    # offsets for the plots
    offset_x = max(x_b) * 0.05
    offset_y = max_y * 0.05

    ax.set_xlim(min_x - offset_x, max_x + offset_x)
    ax.set_ylim(min_y - offset_y, max_y + offset_y)
    
    # Draw distributions
    ax.violinplot(smaller, x_s)
    ax.violinplot(bigger, x_b)
    
    # Compute the means
    smaller_means = [np.mean(x) for x in smaller]
    bigger_means = [np.mean(x) for x in bigger]
    
    # Draw the mean line
    ax.plot(smaller_means, 'o--', markersize=3.0, label=smaller_label)
    ax.plot(bigger_means, 'o--', markersize=3.0, label=bigger_label)
    
    # Annotations
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel, fontsize=16)
    
    ax.legend(fontsize=10.0, loc=legend_loc)
    
    return fig, ax
fig1, ax1 = plot_confidences(full_unnormalized_confidences, 
                 sub_unnormalized_confidences,
                 smaller_label='Mean values of $\mathcal{C}_s^t(\mathcal{E})$ for $H_{sub}$',
                 bigger_label='Mean values of $\mathcal{C}_s^t(\mathcal{E})$ for $H_{full}$',
                 xlabel=r'Number of possible evidenced nodes $|\mathcal{E}|$',
                 ylabel=r'$\mathcal{C}_s^t(\mathcal{E})$')
fig1_svg = os.path.abspath(os.path.join(path_to_images, 'unnorm.svg'))
fig1.savefig(fig1_svg)
fig2, ax2 = plot_confidences(full_normalized_confidences, 
                 sub_normalized_confidences,
                 smaller_label=r"Mean values of $\hat{C}_s^t(\mathcal{E}) for H_{sub}$",
                 bigger_label=r"Mean values of $\hat{C}_s^t(\mathcal{E}) for H_{full}$",
                 xlabel=r"Number of possible evidenced nodes $|\mathcal{E}|$",
                 ylabel=r"$\hat{C}_s^t(\mathcal{E}) = \frac{C_s^t(\mathcal{E})}{max(C_s^t(\mathcal{E}))}$")
fig2_svg = os.path.abspath(os.path.join(path_to_images, 'norm.svg'))
fig2.savefig(fig2_svg)
max_full_unnorm = np.max(full_unnormalized_confidences)[0]
sub_norm_to_big = [np.array(x)/max_full_unnorm for x in sub_unnormalized_confidences]
max_full_unnorm
fig3, ax3 = plot_confidences(sub_normalized_confidences, 
                 sub_norm_to_big,
                 smaller_label=r"Mean values of $\hat{C}_s^t(\mathcal{E}) for H_{sub}$",
                 bigger_label=r"Mean values of $\hat{C}_s^t(\mathcal{E}) for H_{full}$",
                 xlabel=r"Number of possible evidenced nodes $|\mathcal{E}|$",
                 ylabel=r"$\hat{C}_s^t(\mathcal{E}) = \frac{C_s^t(\mathcal{E})}{max_{H_{full}}(C_s^t(\mathcal{E}))}$")
fig3_svg = os.path.abspath(os.path.join(path_to_images, 'subg_to_norm.svg'))
fig3.savefig(fig3_svg)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11533368644067797, 'fraction_numerical': 0.005693855932203389, 'mean_word_length': 5.086220789685737, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '110275', 'license': 'Apache-2.0', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2577, 'n_words': 507, 'path': 'notebooks/results/experiment-1.ipynb', 'repo_name': 'plumdeq/hypothtest', 'size': '7552'}