<jupyter_start><jupyter_text>Random GraphsDraw random Delaunay triangulations<jupyter_code>from graphs import draw_graph, random_delaunay, random_realization
from matplotlib import pyplot as plt
import numpy as np

def draw_random_graph( g, s, t, pos, hidden_state, realization, cut, pruned, ax=None, with_removed=False):
    if ax is None:
        ax = plt.subplot(111)
    hidden_edges = {l[0]: k for l, k in zip(hidden_state, realization)}
    if with_removed:
        removed_edges = list(cut.edges()) + list(pruned.edges())
    else:
        removed_edges = []
    return draw_graph(g, s, t, pos, hidden_edges=hidden_edges,
                       removed_edges=removed_edges, ax=ax)

def draw_lot_of_graphs(rows, columns, width=5, with_removed=False):
    f, axs = plt.subplots(rows, columns, sharey=False, figsize=(columns * width, rows* width))
    if columns == 1:
        axs = np.array([axs]).T
    if rows == 1:
        axs = np.array([axs])
    for i in range(rows):
        for j in range(columns):
            g,  hidden_state, s, t, cut, pruned = random_delaunay(30, 0.5, 7, iters=1)
            realization = random_realization(g, hidden_state, s, t)
            draw_random_graph(g, s, t, g.pos, hidden_state=hidden_state, realization=realization,
                              cut=cut, pruned=pruned, ax=axs[i,j], with_removed=with_removed)
    plt.tight_layout()
draw_lot_of_graphs(2,3)<jupyter_output><empty_output><jupyter_text>ExperimentsOne Experiment is defined by a type of map, a set of classifiers and a set of policies<jupyter_code>from experiment import RandomDelaunayExperiment, all_classifier_samples

exp_config = {'description': 'Random triangulations test',
              'map': {
                  'type': 'delaunay', 
                  'number': 10,
                  'p_not_traversable': 0.5,
                  'n_hidden':7,
                  'size': 30,
                  'iters': 1
              },
              'classifier': {
                  'sigma': [0.5],
                  'samples': 1
              },
              'policy': {
                  'thresholds': [0, 0.5, 1]
              }
             }

exp = RandomDelaunayExperiment('test', exp_config, save=False, pool=1)<jupyter_output><empty_output><jupyter_text>Sample a graphAn experiment repeatedly samples a planning instance made by    - a graph    - source and target nodes    - a list of hidden states    - a realization<jupyter_code>realization, planner, sources = exp.sample(0)
draw_random_graph(planner._graph, sources[0], planner.target, planner._graph.pos,
                  planner.hidden_state, realization, None, None)<jupyter_output><empty_output><jupyter_text>Compute all policy cost using classifiersFor a planning instance, we compute the competitive ration of all policies when using all classifiers<jupyter_code>classifiers = exp_config['classifier']
policies = exp_config['policy']

all_classifier_samples(realization, planner, sources=sources,
                       classifier_config=classifiers,
                       policy_config=policies)<jupyter_output><empty_output><jupyter_text>which is the same as the experiment method<jupyter_code>exp.compute_sample(2)<jupyter_output><empty_output><jupyter_text>that is applied to all maps to compute the final result.<jupyter_code>exp.compute()<jupyter_output>Experiment test: 100%|██████████| 10/10 [00:01<00:00,  4.90it/s]
{'fraction_non_alphanumeric': 0.10565038257798705, 'fraction_numerical': 0.015303119482048263, 'mean_word_length': 3.060931899641577, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '45709', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1062, 'n_words': 258, 'path': 'notebooks/Experiments.ipynb', 'repo_name': 'jeguzzi/resilience', 'size': '3398'}