def export_json_3d_graph(): path_to_csv = '../../data/literature/lesmiserables.csv' graph_structure = read_graph_structure_from_csv(path_to_csv) graph = WeightedGraph(graph_structure) graph.build_graph() graph.build_filtered_subgraphs() graph.get_temporary_hubs_along_filtration() graph.steady_hubs_persistence() graph.ranging_hubs_persistence() graph.plot_steady_persistence_diagram(export_json=True) graph.plot_ranging_persistence_diagram(export_json=True) plt.show()
def reproduce_thesis_figure(graph_structure_number=2): above_max_diagonal_gap = True path_to_csv_1 = './MATRICE DISTANZE.csv' path_to_csv_2 = './MATRICE FREQUENZE.csv' graph_structure = read_csv_distance_matrix(path_to_csv_1) graph_structure_2 = read_csv_frequencies_matrix(path_to_csv_2) graph_structure_1 = get_structure(graph_structure, graph_structure_2, product=False) graph_structure_3 = get_structure(graph_structure_2, graph_structure, product=True) graph_structures = [ graph_structure, graph_structure_1, graph_structure_2, graph_structure_3 ] graph = WeightedGraph(graph_structures[graph_structure_number]) graph.build_graph() graph.build_filtered_subgraphs(weight_transform=identity, sublevel=True) graph.get_temporary_hubs_along_filtration() # Steady graph.steady_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap, gap_number=0) fig, ax = plt.subplots() graph.steady_pd.plot_gudhi( ax, persistence_to_plot=graph.steady_pd.persistence_to_plot) if hasattr(graph.steady_pd, 'proper_cornerpoints_above_gap'): graph.steady_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.steady_pd.mark_points_above_diagonal_gaps(ax) plt.show() print('steady hubs above gap:', graph.steady_pd.proper_cornerpoints_above_gap) from pprint import pprint pprint([(c.vertex, c.persistence) for c in graph.steady_pd.proper_cornerpoints]) # Ranging graph.ranging_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap) fig, ax = plt.subplots() graph.steady_pd.plot_gudhi( ax, persistence_to_plot=graph.ranging_pd.persistence_to_plot) if hasattr(graph.ranging_pd, 'proper_cornerpoints_above_gap'): graph.ranging_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.ranging_pd.mark_points_above_diagonal_gaps(ax) plt.show() print('ranging hubs above gap:', graph.ranging_pd.proper_cornerpoints_above_gap) pprint([(c.vertex, c.persistence) for c in graph.ranging_pd.proper_cornerpoints])
def reproduce_thesis_figure(): above_max_diagonal_gap = True path_to_csv = '../../data/languages/SSWL5_norm.csv' graph_structure = read_csv_distance_matrix(path_to_csv) graph = WeightedGraph(graph_structure) graph.build_graph() graph.build_filtered_subgraphs(weight_transform=max_, sublevel=True) graph.get_temporary_hubs_along_filtration() # Steady graph.steady_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap, gap_number=2) graph.plot_steady_persistence_diagram(show=True) fig, ax = plt.subplots() graph.steady_pd.plot_gudhi( ax, persistence_to_plot=graph.steady_pd.persistence_to_plot) if hasattr(graph.steady_pd, 'proper_cornerpoints_above_gap'): graph.steady_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.steady_pd.mark_points_above_diagonal_gaps(ax) plt.savefig('steady_ling_gap2' + '.pdf', dpi=300) print('Steady hubs:', [c.vertex for c in graph.steady_cornerpoints]) print('steady hubs above gap:', graph.steady_pd.proper_cornerpoints_above_gap) pprint([(c.birth, c.death, c.vertex) for c in graph.steady_pd.proper_cornerpoints_above_gap]) # Ranging graph.ranging_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap, gap_number=2) graph.plot_ranging_persistence_diagram(show=True) fig, ax = plt.subplots() graph.ranging_pd.plot_gudhi( ax, persistence_to_plot=graph.ranging_pd.persistence_to_plot) if hasattr(graph.ranging_pd, 'proper_cornerpoints_above_gap'): graph.ranging_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.ranging_pd.mark_points_above_diagonal_gaps(ax) plt.savefig('ranging_ling_gap2' + '.pdf', dpi=300) print('Ranging hubs:', [c.vertex for c in graph.ranging_cornerpoints]) print('ranging hubs above gap:', graph.ranging_pd.proper_cornerpoints_above_gap) pprint([(c.birth, c.death, c.vertex) for c in graph.ranging_pd.proper_cornerpoints_above_gap])
def reproduce_thesis_figure(): above_max_diagonal_gap = True path_to_csv = '../../data/literature/lesmiserables.csv' graph_structure = read_graph_structure_from_csv(path_to_csv) graph = WeightedGraph(graph_structure) graph.build_graph() graph.build_filtered_subgraphs() graph.get_temporary_hubs_along_filtration() # Steady graph.steady_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap, gap_number=1) graph.plot_steady_persistence_diagram() fig, ax = plt.subplots() graph.steady_pd.plot_gudhi( ax, persistence_to_plot=graph.steady_pd.persistence_to_plot) if hasattr(graph.steady_pd, 'proper_cornerpoints_above_gap'): graph.steady_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.steady_pd.mark_points_above_diagonal_gaps(ax) plt.savefig('gap2_steady' + '.pdf', dpi=300) print('steady hubs above gap:', graph.steady_pd.proper_cornerpoints_above_gap) pprint([(c.birth, c.death, c.vertex) for c in graph.steady_pd.proper_cornerpoints_above_gap]) # Ranging graph.ranging_hubs_persistence( above_max_diagonal_gap=above_max_diagonal_gap, gap_number=1) graph.plot_ranging_persistence_diagram() fig, ax = plt.subplots() graph.ranging_pd.plot_gudhi( ax, persistence_to_plot=graph.ranging_pd.persistence_to_plot) if hasattr(graph.ranging_pd, 'proper_cornerpoints_above_gap'): graph.ranging_pd.plot_nth_widest_gap(ax_handle=ax, n=graph.gap_number) graph.ranging_pd.mark_points_above_diagonal_gaps(ax) plt.savefig('gap2_ranging' + '.pdf', dpi=300) print('ranging hubs above gap:', graph.ranging_pd.proper_cornerpoints_above_gap) pprint([(c.birth, c.death, c.vertex) for c in graph.ranging_pd.proper_cornerpoints_above_gap])
from __future__ import absolute_import, division, print_function from sys import platform if platform == "darwin": import matplotlib matplotlib.use("TkAgg") import sys sys.path.append('../../') import matplotlib.pyplot as plt from perscomb.read_data_from_csv import read_graph_structure_from_csv from perscomb.weighted_graph import WeightedGraph def opp(x): return -x def identity(x): return x path_to_csv = '../../data/neuroscience/celegans_connectome.csv' graph_structure = read_graph_structure_from_csv(path_to_csv) graph = WeightedGraph(graph_structure) graph.build_graph() graph.build_filtered_subgraphs(weight_transform=opp, sublevel=True) graph.get_temporary_hubs_along_filtration() graph.ranging_hubs_persistence() graph.plot_ranging_persistence_diagram(export_json='./c_elegans')
def get_structure(self, graph, index): if self.persistence_function == "steady": nodes_color_map,\ nodelist,\ node_size, cornerpoints = graph.plot_steady_persistence_diagram(return_attr = True) elif self.persistence_function == "ranging": nodes_color_map,\ nodelist,\ node_size, cornerpoints = graph.plot_ranging_persistence_diagram(return_attr = True) return graph.export_graph_and_hubs_as_dict(nodes_color_map, nodelist, node_size, cornerpoints, observation=index) if __name__ == "__main__": path_to_folder = 'data/literature/GOT/' csv_files = ['1', '2', '3', '45'] graphs = [] for file_name in csv_files: path_to_csv = os.path.join(path_to_folder, file_name + '.csv') graph_structure = read_graph_structure_from_csv(path_to_csv) graphs.append(WeightedGraph(graph_structure)) tvg = TimeVaryingHubs(graphs) tvg.compute_persistence(persistence_function="ranging") tvg.export_csv_for_plot(save_as='./got_dynamical_ranging.csv')