def __init__(self, n_nodes, ux, spectral_profile, type_graph="erdos", type_noise="gaussian", save_history=True, seed=None, **kargs): ####### The algorithm asks the user a spectral_profile for the Graph filter that will be applied ### to white noise so the output signal is stationary with respect to the graph structure. #### This section initialize the structure of the graph signal ### Input # n_nodes=number of nodes # ux= mean of the signal # spectral_profile= a function generating the power spectral density of the sygnal. # type_graph=available graph model (erdos,euclidean,barabasi_albert) # type_noise = distribution of the noise (gaussian,uniform) that will be used to ge self.n_nodes = n_nodes self.type_graph = type_graph self.type_noise = type_noise self.ux = ux self.spectral_profile = spectral_profile self.seed = seed if type_graph == "erdos": self.G = graphs.ErdosRenyi(self.n_nodes, kargs['p'], seed=self.seed) self.G.set_coordinates() if type_graph == "barabasi_albert": self.G = graphs.BarabasiAlbert(self.n_nodes, m=kargs['m'], m0=kargs['m'], seed=self.seed) self.G.set_coordinates() if type_graph == "Minnesota": self.G = graphs.Minnesota() self.generate_fourier() self.generate_filter()
# import numpy as np # from scipy import sparse # # from pygsp import utils # from pygsp.graphs import Graph import pygsp.graphs as graphs import matplotlib.pyplot as plt G = graphs.Minnesota() fig, axes = plt.subplots(1, 2) _ = axes[0].spy(G.W, markersize=0.5) _ = G.plot(ax=axes[1]) plt.show()
def test_minnesota(self): graphs.Minnesota()
def real(N, graph_name, connected=True): r""" A convenience method for loading toy graphs that have been collected from the internet. Parameters: ---------- N : int The number of nodes. graph_name : a string Use to select which graph is returned. Choices include * airfoil Graph from airflow simulation http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.50.9217&rep=rep1&type=pdf http://networkrepository.com/airfoil1.php * yeast Network of protein-to-protein interactions in budding yeast. http://networkrepository.com/bio-yeast.php * minnesota Minnesota road network. I am using the version provided by the PyGSP software package (initially taken from the MatlabBGL library.) * bunny The Stanford bunny is a computer graphics 3D test model developed by Greg Turk and Marc Levoy in 1994 at Stanford University I am using the version provided by the PyGSP software package. connected : Boolean Set to True if only the giant component is to be returned. """ directory = os.path.dirname(graph_utils.__file__) + '/data/' tries = 0 while True: tries = tries + 1 if graph_name == 'airfoil': G = graphs.Airfoil() G = graphs.Graph(W=G.W[0:N, 0:N], coords=G.coords[0:N, :]) elif graph_name == 'yeast': file = directory + 'bio-yeast.npy' W = np.load(file) G = graphs.Graph(W=W[0:N, 0:N]) elif graph_name == 'minnesota': G = graphs.Minnesota() W = G.W.astype(np.float) G = graphs.Graph(W=W[0:N, 0:N], coords=G.coords[0:N, :]) elif graph_name == 'bunny': G = graphs.Bunny() W = G.W.astype(np.float) G = graphs.Graph(W=W[0:N, 0:N], coords=G.coords[0:N, :]) if connected == False or G.is_connected(): break if tries > 1: print( 'WARNING: disconnected graph.. trying to use the giant component' ) G, _ = graph_utils.get_giant_component(G) break return G
def real(N, graph_name, connected=True): r""" A convenience method for loading toy graphs that have been collected from the internet. Parameters: ---------- N : int The number of nodes. Set N=-1 to return the entire graph. graph_name : a string Use to select which graph is returned. Choices include * airfoil Graph from airflow simulation http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.50.9217&rep=rep1&type=pdf http://networkrepository.com/airfoil1.php * yeast Network of protein-to-protein interactions in budding yeast. http://networkrepository.com/bio-yeast.php * minnesota Minnesota road network. I am using the version provided by the PyGSP software package (initially taken from the MatlabBGL library.) * bunny The Stanford bunny is a computer graphics 3D test model developed by Greg Turk and Marc Levoy in 1994 at Stanford University I am using the version provided by the PyGSP software package. connected : Boolean Set to True if only the giant component is to be returned. """ directory = os.path.join( os.path.dirname(os.path.dirname(graph_utils.__file__)), "data" ) tries = 0 while True: tries = tries + 1 if graph_name == "airfoil": G = graphs.Airfoil() G = graphs.Graph(W=G.W[0:N, 0:N], coords=G.coords[0:N, :]) elif graph_name == "yeast": W = download_yeast() G = graphs.Graph(W=W[0:N, 0:N]) elif graph_name == "minnesota": G = graphs.Minnesota() W = G.W.astype(np.float) G = graphs.Graph(W=W[0:N, 0:N], coords=G.coords[0:N, :]) elif graph_name == "bunny": G = graphs.Bunny() W = G.W.astype(np.float) G = graphs.Graph(W=W[0:N, 0:N], coords=G.coords[0:N, :]) if connected == False or G.is_connected(): break if tries > 1: print("WARNING: Disconnected graph. Using the giant component.") G, _ = graph_utils.get_giant_component(G) break if not hasattr(G, 'coords'): try: import networkx as nx graph = nx.from_scipy_sparse_matrix(G.W) pos = nx.nx_agraph.graphviz_layout(graph, prog='neato') G.set_coordinates(np.array(list(pos.values()))) except ImportError: G.set_coordinates() return G
def test_Minnesota(): G = graphs.Minnesota()
def test_Minnesota(): G = graphs.Minnesota() needed_attributes_testing(G)