|
3 | 3 | import numpy as np |
4 | 4 | import abc |
5 | 5 | import pygsp |
6 | | -from sklearn.utils.fixes import signature |
| 6 | +from inspect import signature |
7 | 7 | from sklearn.decomposition import PCA, TruncatedSVD |
8 | 8 | from sklearn.preprocessing import normalize |
9 | | -from sklearn.utils.graph import graph_shortest_path |
10 | 9 | from scipy import sparse |
11 | 10 | import warnings |
12 | 11 | import numbers |
13 | 12 | import tasklogger |
| 13 | +import pickle |
| 14 | +import sys |
14 | 15 |
|
15 | 16 | try: |
16 | 17 | import pandas as pd |
@@ -106,10 +107,10 @@ class Data(Base): |
106 | 107 | def __init__(self, data, n_pca=None, random_state=None, **kwargs): |
107 | 108 |
|
108 | 109 | self._check_data(data) |
109 | | - if n_pca is not None and data.shape[1] <= n_pca: |
| 110 | + if n_pca is not None and np.min(data.shape) <= n_pca: |
110 | 111 | warnings.warn("Cannot perform PCA to {} dimensions on " |
111 | | - "data with {} dimensions".format(n_pca, |
112 | | - data.shape[1]), |
| 112 | + "data with min(n_samples, n_features) = {}".format( |
| 113 | + n_pca, np.min(data.shape)), |
113 | 114 | RuntimeWarning) |
114 | 115 | n_pca = None |
115 | 116 | try: |
@@ -316,7 +317,7 @@ class BaseGraph(with_metaclass(abc.ABCMeta, Base)): |
316 | 317 | 'theta' : min-max |
317 | 318 | 'none' : no symmetrization |
318 | 319 |
|
319 | | - theta: float (default: 0.5) |
| 320 | + theta: float (default: 1) |
320 | 321 | Min-max symmetrization constant. |
321 | 322 | K = `theta * min(K, K.T) + (1 - theta) * max(K, K.T)` |
322 | 323 |
|
@@ -385,7 +386,7 @@ def _check_symmetrization(self, kernel_symm, theta): |
385 | 386 | if theta is None: |
386 | 387 | warnings.warn("kernel_symm='theta' but theta not given. " |
387 | 388 | "Defaulting to theta=0.5.") |
388 | | - self.theta = theta = 0.5 |
| 389 | + self.theta = theta = 1 |
389 | 390 | elif not isinstance(theta, numbers.Number) or \ |
390 | 391 | theta < 0 or theta > 1: |
391 | 392 | raise ValueError("theta {} not recognized. Expected " |
@@ -636,6 +637,23 @@ def to_igraph(self, attribute="weight", **kwargs): |
636 | 637 | return ig.Graph.Weighted_Adjacency(utils.to_dense(W).tolist(), |
637 | 638 | attr=attribute, **kwargs) |
638 | 639 |
|
| 640 | + def to_pickle(self, path): |
| 641 | + """Save the current Graph to a pickle. |
| 642 | +
|
| 643 | + Parameters |
| 644 | + ---------- |
| 645 | + path : str |
| 646 | + File path where the pickled object will be stored. |
| 647 | + """ |
| 648 | + if int(sys.version.split(".")[1]) < 7 and isinstance(self, pygsp.graphs.Graph): |
| 649 | + # python 3.5, 3.6 |
| 650 | + logger = self.logger |
| 651 | + self.logger = logger.name |
| 652 | + with open(path, 'wb') as f: |
| 653 | + pickle.dump(self, f) |
| 654 | + if int(sys.version.split(".")[1]) < 7 and isinstance(self, pygsp.graphs.Graph): |
| 655 | + self.logger = logger |
| 656 | + |
639 | 657 |
|
640 | 658 | class PyGSPGraph(with_metaclass(abc.ABCMeta, pygsp.graphs.Graph, Base)): |
641 | 659 | """Interface between BaseGraph and PyGSP. |
|
0 commit comments