@@ -248,7 +248,7 @@ def _fc(timeseries, mean=False):
248248
249249@due .dcite (references .SHUMAN_2013 )
250250def smoothness (laplacian , signal ):
251- """Compute the smoothness of a signal over the graph corresponding to given laplacian .
251+ """Compute the smoothness of a signal (as defined in [1]) over the graph corresponding to given Laplacian .
252252
253253 Parameters
254254 ----------
@@ -270,7 +270,31 @@ def smoothness(laplacian, signal):
270270 Processing Magazine, vol. 30, no. 3, pp. 83-98, May 2013
271271 """
272272 LGR .info ("Compute signal smoothness." )
273- return np .dot (signal .T , np .dot (laplacian , signal ))
273+
274+ # Checking shape of signal
275+ if signal .ndim == 1 :
276+ LGR .warning (
277+ "2D array required, but signal is a vector. Adding empty dimension."
278+ )
279+ signal = np .expand_dims (signal , - 1 )
280+ elif signal .ndim > 2 :
281+ raise ValueError ("Signal should be a 2D array." )
282+
283+ # Checking if laplacian is square
284+ if laplacian .shape [0 ] != laplacian .shape [1 ]:
285+ raise ValueError ("Laplacian should be a square matrix." )
286+
287+ # Checking that the dimensions of signal and laplacian are compatible
288+ if signal .shape [0 ] != laplacian .shape [0 ]:
289+ if signal .shape [1 ] == laplacian .shape [0 ]:
290+ LGR .warning (
291+ "It seems that the signal needs to be transposed to the correct shape."
292+ )
293+ signal = np .swapaxes (signal , 0 , 1 )
294+ else :
295+ raise ValueError ("The dimensions of the signal and Laplacian don't match." )
296+
297+ return np .matmul (signal .T , np .matmul (laplacian , signal ))
274298
275299
276300"""
0 commit comments