Skip to content

Commit

Permalink
Deprecate non-"matrix" names in laplacian.
Browse files Browse the repository at this point in the history
Use laplacian_matrix, directed_laplacian_matrix, and normalized_laplacian_matrix only and deprecate other name aliases.
  • Loading branch information
hagberg committed Jan 6, 2013
1 parent 38e47ff commit 5a91b51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
21 changes: 8 additions & 13 deletions networkx/linalg/laplacianmatrix.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Laplacian matrix of graphs.
"""
# Copyright (C) 2004-2011 by
# Copyright (C) 2004-2013 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
Expand All @@ -10,16 +10,16 @@
import networkx as nx
from networkx.utils import require, not_implemented_for

__author__ = "\n".join(['Aric Hagberg (hagberg@lanl.gov)',
__author__ = "\n".join(['Aric Hagberg <aric.hagberg@gmail.com>',
'Pieter Swart (swart@lanl.gov)',
'Dan Schult(dschult@colgate.edu)'])
'Dan Schult (dschult@colgate.edu)',
'Alejandro Weinstein <alejandro.weinstein@gmail.com>'])

__all__ = ['laplacian', 'generalized_laplacian','normalized_laplacian',
'laplacian_matrix', 'generalized_laplacian','normalized_laplacian',
'directed_laplacian',
__all__ = ['laplacian_matrix',
'normalized_laplacian_matrix',
'directed_laplacian_matrix',
]


def laplacian_matrix(G, nodelist=None, weight='weight'):
"""Return the Laplacian matrix of G.
Expand Down Expand Up @@ -167,7 +167,7 @@ def normalized_laplacian_matrix(G, nodelist=None, weight='weight'):
@require('numpy')
@not_implemented_for('undirected')
@not_implemented_for('multigraph')
def directed_laplacian(G, nodelist=None, weight='weight', walk_type=None, alpha=0.95):
def directed_laplacian_matrix(G, nodelist=None, weight='weight', walk_type=None, alpha=0.95):
r"""Return the directed Laplacian matrix of G.
The graph directed Laplacian is the matrix
Expand Down Expand Up @@ -273,11 +273,6 @@ def directed_laplacian(G, nodelist=None, weight='weight', walk_type=None, alpha=

return I - (Q + Q.T) /2.0

combinatorial_laplacian=laplacian_matrix
generalized_laplacian=normalized_laplacian_matrix
normalized_laplacian=normalized_laplacian_matrix
laplacian=laplacian_matrix

# fixture for nose tests
def setup_module(module):
from nose import SkipTest
Expand Down
37 changes: 14 additions & 23 deletions networkx/linalg/tests/test_laplacian.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,13 @@ def test_laplacian(self):
[ 0, 0, 0, 0, 0]])
WL=0.5*NL
OL=0.3*NL
assert_equal(nx.laplacian(self.G),NL)
assert_equal(nx.laplacian(self.MG),NL)
assert_equal(nx.laplacian(self.G,nodelist=[0,1]),
assert_equal(nx.laplacian_matrix(self.G),NL)
assert_equal(nx.laplacian_matrix(self.MG),NL)
assert_equal(nx.laplacian_matrix(self.G,nodelist=[0,1]),
numpy.array([[ 1, -1],[-1, 1]]))
assert_equal(nx.laplacian(self.WG),WL)
assert_equal(nx.laplacian(self.WG,weight=None),NL)
assert_equal(nx.laplacian(self.WG,weight='other'),OL)

def test_generalized_laplacian(self):
"Generalized Graph Laplacian"
GL=numpy.array([[ 1.00, -0.408, -0.408, -0.577, 0.00],
[-0.408, 1.00, -0.50, 0.00 , 0.00],
[-0.408, -0.50, 1.00, 0.00, 0.00],
[-0.577, 0.00, 0.00, 1.00, 0.00],
[ 0.00, 0.00, 0.00, 0.00, 0.00]])
assert_almost_equal(nx.generalized_laplacian(self.G),GL,decimal=3)
assert_equal(nx.laplacian_matrix(self.WG),WL)
assert_equal(nx.laplacian_matrix(self.WG,weight=None),NL)
assert_equal(nx.laplacian_matrix(self.WG,weight='other'),OL)

def test_normalized_laplacian(self):
"Generalized Graph Laplacian"
Expand All @@ -69,11 +60,11 @@ def test_normalized_laplacian(self):
[-0.3536, 0. , 0. , 0.5 , 0.],
[ 0. , 0. , 0. , 0. , 0.]])

assert_almost_equal(nx.normalized_laplacian(self.G),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian(self.MG),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian(self.WG),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian(self.WG,weight='other'),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian(self.Gsl), Lsl, decimal=3)
assert_almost_equal(nx.normalized_laplacian_matrix(self.G),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian_matrix(self.MG),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian_matrix(self.WG),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian_matrix(self.WG,weight='other'),GL,decimal=3)
assert_almost_equal(nx.normalized_laplacian_matrix(self.Gsl), Lsl, decimal=3)

def test_directed_laplacian(self):
"Directed Laplacian"
Expand All @@ -89,7 +80,7 @@ def test_directed_laplacian(self):
[-0.0291, -0.0536, -0.0278, 0.9833, -0.4878, -0.6675],
[-0.0231, -0.0589, -0.0896, -0.4878, 0.9833, -0.2078],
[-0.0261, -0.0554, -0.0251, -0.6675, -0.2078, 0.9833]])
assert_almost_equal(nx.directed_laplacian(G, alpha=0.9), GL, decimal=3)
assert_almost_equal(nx.directed_laplacian_matrix(G, alpha=0.9), GL, decimal=3)

# Make the graph strongly connected, so we can use a random and lazy walk
G.add_edges_from((((2,5), (6,1))))
Expand All @@ -99,12 +90,12 @@ def test_directed_laplacian(self):
[ 0. , 0. , 0. , 1. , -0.5 , -0.5 ],
[ 0. , -0.3162, -0.0913, -0.5 , 1. , -0.25 ],
[-0.3227, 0. , 0. , -0.5 , -0.25 , 1. ]])
assert_almost_equal(nx.directed_laplacian(G, walk_type='random'), GL, decimal=3)
assert_almost_equal(nx.directed_laplacian_matrix(G, walk_type='random'), GL, decimal=3)

GL = numpy.array([[ 0.5 , -0.1531, -0.2357, 0. , 0. , -0.1614],
[-0.1531, 0.5 , -0.0722, 0. , -0.1581, 0. ],
[-0.2357, -0.0722, 0.5 , 0. , -0.0456, 0. ],
[ 0. , 0. , 0. , 0.5 , -0.25 , -0.25 ],
[ 0. , -0.1581, -0.0456, -0.25 , 0.5 , -0.125 ],
[-0.1614, 0. , 0. , -0.25 , -0.125 , 0.5 ]])
assert_almost_equal(nx.directed_laplacian(G, walk_type='lazy'), GL, decimal=3)
assert_almost_equal(nx.directed_laplacian_matrix(G, walk_type='lazy'), GL, decimal=3)

0 comments on commit 5a91b51

Please sign in to comment.