@@ -78,7 +78,7 @@ def _graph_is_connected(graph):
78
78
return _graph_connected_component (graph , 0 ).sum () == graph .shape [0 ]
79
79
80
80
81
- def _set_diag (laplacian , value ):
81
+ def _set_diag (laplacian , value , norm_laplacian ):
82
82
"""Set the diagonal of the laplacian matrix and convert it to a
83
83
sparse format well suited for eigenvalue decomposition
84
84
@@ -88,6 +88,8 @@ def _set_diag(laplacian, value):
88
88
The graph laplacian
89
89
value : float
90
90
The value of the diagonal
91
+ norm_laplacian : bool
92
+ Whether the value of the diagonal should be changed or not
91
93
92
94
Returns
93
95
-------
@@ -99,11 +101,13 @@ def _set_diag(laplacian, value):
99
101
n_nodes = laplacian .shape [0 ]
100
102
# We need all entries in the diagonal to values
101
103
if not sparse .isspmatrix (laplacian ):
102
- laplacian .flat [::n_nodes + 1 ] = value
104
+ if norm_laplacian :
105
+ laplacian .flat [::n_nodes + 1 ] = value
103
106
else :
104
107
laplacian = laplacian .tocoo ()
105
- diag_idx = (laplacian .row == laplacian .col )
106
- laplacian .data [diag_idx ] = value
108
+ if norm_laplacian :
109
+ diag_idx = (laplacian .row == laplacian .col )
110
+ laplacian .data [diag_idx ] = value
107
111
# If the matrix has a small number of diagonals (as in the
108
112
# case of structured matrices coming from images), the
109
113
# dia format might be best suited for matvec products:
@@ -229,7 +233,7 @@ def spectral_embedding(adjacency, n_components=8, eigen_solver=None,
229
233
# /lobpcg/lobpcg.py#L237
230
234
# or matlab:
231
235
# http://www.mathworks.com/matlabcentral/fileexchange/48-lobpcg-m
232
- laplacian = _set_diag (laplacian , 1 )
236
+ laplacian = _set_diag (laplacian , 1 , norm_laplacian )
233
237
234
238
# Here we'll use shift-invert mode for fast eigenvalues
235
239
# (see http://docs.scipy.org/doc/scipy/reference/tutorial/arpack.html
@@ -268,7 +272,7 @@ def spectral_embedding(adjacency, n_components=8, eigen_solver=None,
268
272
# lobpcg needs double precision floats
269
273
laplacian = check_array (laplacian , dtype = np .float64 ,
270
274
accept_sparse = True )
271
- laplacian = _set_diag (laplacian , 1 )
275
+ laplacian = _set_diag (laplacian , 1 , norm_laplacian )
272
276
ml = smoothed_aggregation_solver (check_array (laplacian , 'csr' ))
273
277
M = ml .aspreconditioner ()
274
278
X = random_state .rand (laplacian .shape [0 ], n_components + 1 )
@@ -292,7 +296,7 @@ def spectral_embedding(adjacency, n_components=8, eigen_solver=None,
292
296
lambdas , diffusion_map = eigh (laplacian )
293
297
embedding = diffusion_map .T [:n_components ] * dd
294
298
else :
295
- laplacian = _set_diag (laplacian , 1 )
299
+ laplacian = _set_diag (laplacian , 1 , norm_laplacian )
296
300
# We increase the number of eigenvectors requested, as lobpcg
297
301
# doesn't behave well in low dimension
298
302
X = random_state .rand (laplacian .shape [0 ], n_components + 1 )
0 commit comments