@@ -311,12 +311,12 @@ class BaseGraph(with_metaclass(abc.ABCMeta, Base)):
311311 Defines method of MNN symmetrization.
312312 '+' : additive
313313 '*' : multiplicative
314- 'gamma ' : min-max
314+ 'theta ' : min-max
315315 'none' : no symmetrization
316316
317- gamma : float (default: 0.5)
317+ theta : float (default: 0.5)
318318 Min-max symmetrization constant.
319- K = `gamma * min(K, K.T) + (1 - gamma ) * max(K, K.T)`
319+ K = `theta * min(K, K.T) + (1 - theta ) * max(K, K.T)`
320320
321321 initialize : `bool`, optional (default : `True`)
322322 if false, don't create the kernel matrix.
@@ -337,11 +337,20 @@ class BaseGraph(with_metaclass(abc.ABCMeta, Base)):
337337 """
338338
339339 def __init__ (self , kernel_symm = '+' ,
340+ theta = None ,
340341 gamma = None ,
341342 initialize = True , ** kwargs ):
343+ if gamma is not None :
344+ warnings .warn ("gamma is deprecated. "
345+ "Setting theta={}" .format (gamma ), FutureWarning )
346+ theta = gamma
347+ if kernel_symm == 'gamma' :
348+ warnings .warn ("kernel_symm='gamma' is deprecated. "
349+ "Setting kernel_symm='theta'" , FutureWarning )
350+ kernel_symm = 'theta'
342351 self .kernel_symm = kernel_symm
343- self .gamma = gamma
344- self ._check_symmetrization (kernel_symm , gamma )
352+ self .theta = theta
353+ self ._check_symmetrization (kernel_symm , theta )
345354
346355 if initialize :
347356 tasklogger .log_debug ("Initializing kernel..." )
@@ -350,25 +359,25 @@ def __init__(self, kernel_symm='+',
350359 tasklogger .log_debug ("Not initializing kernel." )
351360 super ().__init__ (** kwargs )
352361
353- def _check_symmetrization (self , kernel_symm , gamma ):
354- if kernel_symm not in ['+' , '*' , 'gamma ' , None ]:
362+ def _check_symmetrization (self , kernel_symm , theta ):
363+ if kernel_symm not in ['+' , '*' , 'theta ' , None ]:
355364 raise ValueError (
356365 "kernel_symm '{}' not recognized. Choose from "
357- "'+', '*', 'gamma ', or 'none'." .format (kernel_symm ))
358- elif kernel_symm != 'gamma ' and gamma is not None :
359- warnings .warn ("kernel_symm='{}' but gamma is not None. "
360- "Setting kernel_symm='gamma '." .format (kernel_symm ))
361- self .kernel_symm = kernel_symm = 'gamma '
362-
363- if kernel_symm == 'gamma ' :
364- if gamma is None :
365- warnings .warn ("kernel_symm='gamma ' but gamma not given. "
366- "Defaulting to gamma =0.5." )
367- self .gamma = gamma = 0.5
368- elif not isinstance (gamma , numbers .Number ) or \
369- gamma < 0 or gamma > 1 :
370- raise ValueError ("gamma {} not recognized. Expected "
371- "a float between 0 and 1" .format (gamma ))
366+ "'+', '*', 'theta ', or 'none'." .format (kernel_symm ))
367+ elif kernel_symm != 'theta ' and theta is not None :
368+ warnings .warn ("kernel_symm='{}' but theta is not None. "
369+ "Setting kernel_symm='theta '." .format (kernel_symm ))
370+ self .kernel_symm = kernel_symm = 'theta '
371+
372+ if kernel_symm == 'theta ' :
373+ if theta is None :
374+ warnings .warn ("kernel_symm='theta ' but theta not given. "
375+ "Defaulting to theta =0.5." )
376+ self .theta = theta = 0.5
377+ elif not isinstance (theta , numbers .Number ) or \
378+ theta < 0 or theta > 1 :
379+ raise ValueError ("theta {} not recognized. Expected "
380+ "a float between 0 and 1" .format (theta ))
372381
373382 def _build_kernel (self ):
374383 """Private method to build kernel matrix
@@ -400,26 +409,26 @@ def symmetrize_kernel(self, K):
400409 elif self .kernel_symm == "*" :
401410 tasklogger .log_debug ("Using multiplication symmetrization." )
402411 K = K .multiply (K .T )
403- elif self .kernel_symm == 'gamma ' :
412+ elif self .kernel_symm == 'theta ' :
404413 tasklogger .log_debug (
405- "Using gamma symmetrization (gamma = {})." .format (self .gamma ))
406- K = self .gamma * elementwise_minimum (K , K .T ) + \
407- (1 - self .gamma ) * elementwise_maximum (K , K .T )
414+ "Using theta symmetrization (theta = {})." .format (self .theta ))
415+ K = self .theta * elementwise_minimum (K , K .T ) + \
416+ (1 - self .theta ) * elementwise_maximum (K , K .T )
408417 elif self .kernel_symm is None :
409418 tasklogger .log_debug ("Using no symmetrization." )
410419 pass
411420 else :
412421 # this should never happen
413422 raise ValueError (
414- "Expected kernel_symm in ['+', '*', 'gamma ' or None]. "
415- "Got {}" .format (self .gamma ))
423+ "Expected kernel_symm in ['+', '*', 'theta ' or None]. "
424+ "Got {}" .format (self .theta ))
416425 return K
417426
418427 def get_params (self ):
419428 """Get parameters from this object
420429 """
421430 return {'kernel_symm' : self .kernel_symm ,
422- 'gamma ' : self .gamma }
431+ 'theta ' : self .theta }
423432
424433 def set_params (self , ** params ):
425434 """Set parameters on this object
@@ -429,7 +438,7 @@ def set_params(self, **params):
429438 Valid parameters:
430439 Invalid parameters: (these would require modifying the kernel matrix)
431440 - kernel_symm
432- - gamma
441+ - theta
433442
434443 Parameters
435444 ----------
@@ -439,8 +448,8 @@ def set_params(self, **params):
439448 -------
440449 self
441450 """
442- if 'gamma ' in params and params ['gamma ' ] != self .gamma :
443- raise ValueError ("Cannot update gamma . Please create a new graph" )
451+ if 'theta ' in params and params ['theta ' ] != self .theta :
452+ raise ValueError ("Cannot update theta . Please create a new graph" )
444453 if 'kernel_symm' in params and \
445454 params ['kernel_symm' ] != self .kernel_symm :
446455 raise ValueError (
@@ -535,6 +544,42 @@ def build_kernel(self):
535544 """
536545 raise NotImplementedError
537546
547+ def to_pygsp (self , ** kwargs ):
548+ """Convert to a PyGSP graph
549+
550+ For use only when the user means to create the graph using
551+ the flag `use_pygsp=True`, and doesn't wish to recompute the kernel.
552+ Creates a graphtools.graphs.TraditionalGraph with a precomputed
553+ affinity matrix which also inherits from pygsp.graphs.Graph.
554+
555+ Parameters
556+ ----------
557+ kwargs
558+ keyword arguments for graphtools.Graph
559+
560+ Returns
561+ -------
562+ G : graphtools.base.PyGSPGraph, graphtools.graphs.TraditionalGraph
563+ """
564+ from . import api
565+ if 'precomputed' in kwargs :
566+ if kwargs ['precomputed' ] != 'affinity' :
567+ warnings .warn (
568+ "Cannot build PyGSPGraph with precomputed={}. "
569+ "Using 'affinity' instead." .format (kwargs ['precomputed' ]),
570+ UserWarning )
571+ del kwargs ['precomputed' ]
572+ if 'use_pygsp' in kwargs :
573+ if kwargs ['use_pygsp' ] is not True :
574+ warnings .warn (
575+ "Cannot build PyGSPGraph with use_pygsp={}. "
576+ "Use True instead." .format (kwargs ['use_pygsp' ]),
577+ UserWarning )
578+ del kwargs ['use_pygsp' ]
579+ return api .Graph (self .K ,
580+ precomputed = "affinity" , use_pygsp = True ,
581+ ** kwargs )
582+
538583
539584class PyGSPGraph (with_metaclass (abc .ABCMeta , pygsp .graphs .Graph , Base )):
540585 """Interface between BaseGraph and PyGSP.
0 commit comments