Graphes#

Distance#

class mlstatpy.graph.graph_distance.GraphDistance(edge_list, vertex_label=None, add_loop=False, weight_vertex=1.0, weight_edge=1.0)[source][source]

Defines a graph to compute a distance between two graphs.

Compute a distance between two graphs.

See Distance between two graphs.

<<<

import copy
from mlstatpy.graph import GraphDistance

# We define two graphs as list of edges.
graph1 = [
    ("a", "b"),
    ("b", "c"),
    ("b", "X"),
    ("X", "c"),
    ("c", "d"),
    ("d", "e"),
    ("0", "b"),
]
graph2 = [
    ("a", "b"),
    ("b", "c"),
    ("b", "X"),
    ("X", "c"),
    ("c", "t"),
    ("t", "d"),
    ("d", "e"),
    ("d", "g"),
]

# We convert them into objects GraphDistance.
graph1 = GraphDistance(graph1)
graph2 = GraphDistance(graph2)

distance, graph = graph1.distance_matching_graphs_paths(graph2, use_min=False)

print("distance", distance)
print("common paths:", graph)

>>>

    distance 0.3318250377073907
    common paths: 0
    X
    a
    b
    c
    d
    e
    00
    11
    g
    t
    a -> b []
    b -> c []
    b -> X []
    X -> c []
    c -> d []
    d -> e []
    0 -> b []
    00 -> a []
    00 -> 0 []
    e -> 11 []
    c -> 2a.t []
    2a.t -> d []
    d -> 2a.g []
    2a.g -> 11 []
distance_matching_graphs_paths(graph2, function_mach_vertices=None, function_match_edges=None, noClean=False, store=None, use_min=True, weight_vertex=1.0, weight_edge=1.0, verbose=0)[source][source]

Computes an alignment between two graphs.

Paramètres:
  • graph2 – the other graph

  • function_mach_vertices – function which gives a distance between two vertices, if None, it take the output of get_matching_functions()

  • function_match_edges – function which gives a distance bewteen two edges, if None, it take the output of get_matching_functions()

  • noClean – if True, clean unmatched vertices and edges

  • store – if None, does nothing, if it is a dictionary, the function will store here various information about how the matching was operated

  • use_min – @see me edit_distance_path

  • weight_vertex – a weight for every vertex

  • weight_edge – a weight for every edge

  • verbose – display some progress with tqdm

Renvoie:

2 tuple (a distance, a graph containing the aligned paths between the two graphs)

See Distance between two graphs.