Пример #1
0
 def get_number_of_components_of_graph(graph, min_weight=None, pre_callback=None):
     if pre_callback:
         graph = pre_callback(graph)
     igraph_graph = igraph.Graph.Weighted_Adjacency(graph.tolist(), mode=igraph.ADJ_MAX)
     if min_weight is not None:
         GiantComponentDeath.remove_weighted_edges(igraph_graph, min_weight)
     components = len(igraph_graph.components())
     return components
 def get_giant_component_destruction_curves(filename,
                                            window_size,
                                            until=-1,
                                            calculate_on=-1,
                                            count='components',
                                            adjusted=True):
     filenames = [('', filename)]
     all_graph_matrices = SwarmAnalyzer.get_graph_matrices_from_files(
         filenames,
         windows_size=[window_size],
         until=until,
         calculate_on=calculate_on)
     graph_matrices = all_graph_matrices[''][window_size]
     # the maximum is 2*tw, where tw is the window size, but if the graph is from an iteration t that is less than
     # tw, then the maximum is 2*t, therefore:
     if calculate_on == -1:
         weight_normalize = [
             2.0 * i if i < window_size else 2.0 * window_size
             for i in range(len(graph_matrices))
         ]
     else:
         weight_normalize = [
             2.0 * calculate_on if calculate_on < window_size else 2.0 *
             window_size
         ]
     curves = GiantComponentDeath.create_giant_component_curves(
         graph_matrices,
         adjusted=adjusted,
         include_zero=False,
         weight_normalize=weight_normalize,
         count=count)
     return curves
Пример #3
0
 def read_files_and_plot_destruction_curves(filenames,
                                            windows_size,
                                            calculate_on,
                                            count='components'):
     graph_matrices = SwarmAnalyzer.get_graph_matrices_from_files(
         filenames, windows_size=windows_size, calculate_on=calculate_on)
     normalize = [2 * i for i in windows_size]
     pd_datas = []
     for title, _ in filenames:
         graphs = [graph_matrices[title][i] for i in windows_size]
         graphs = map(lambda x: x[0],
                      graphs)  # this was a calculate_on call
         curves_areas = GiantComponentDeath.create_giant_component_curves(
             graphs, weight_normalize=normalize, count=count)
         pd_datas.append((title, dict(zip(windows_size, curves_areas))))
     GiantComponentDeathPlotter.giant_component_death_curve(calculate_on,
                                                            pd_datas,
                                                            xlim=(0, 1.0),
                                                            figsize=(4.5,
                                                                     4),
                                                            count=count)