示例#1
0
 def test_dirichlet_energy(self, n_vertices=100):
     r"""The Dirichlet energy is defined as the norm of the gradient."""
     signal = np.random.RandomState(42).uniform(size=n_vertices)
     for lap_type in ['combinatorial', 'normalized']:
         graph = graphs.BarabasiAlbert(n_vertices)
         graph.compute_differential_operator()
         energy = graph.dirichlet_energy(signal)
         grad_norm = np.sum(graph.grad(signal)**2)
         np.testing.assert_allclose(energy, grad_norm)
示例#2
0
 def test_networkx_signal_export(self):
     graph = graphs.BarabasiAlbert(N=100, seed=42)
     rs = np.random.RandomState(42)
     signal1 = rs.normal(size=graph.N)
     signal2 = rs.normal(size=graph.N)
     graph.set_signal(signal1, "signal1")
     graph.set_signal(signal2, "signal2")
     graph_nx = graph.to_networkx()
     for i in range(graph.N):
         self.assertEqual(graph_nx.node[i]["signal1"], signal1[i])
         self.assertEqual(graph_nx.node[i]["signal2"], signal2[i])
     # invalid signal type
     graph = graphs.Path(3)
     graph.set_signal(np.array(['a', 'b', 'c']), 'sig')
     self.assertRaises(ValueError, graph.to_networkx)
示例#3
0
    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()