rename ensure_symmetric -> test_symmetric
This commit is contained in:
parent
7794d90471
commit
a21957e85c
|
|
@ -11,7 +11,7 @@ import warnings
|
|||
|
||||
from ..base import BaseEstimator
|
||||
from ..metrics import euclidean_distances
|
||||
from ..utils import check_random_state, check_array, ensure_symmetric
|
||||
from ..utils import check_random_state, check_array, check_symmetric
|
||||
from ..externals.joblib import Parallel
|
||||
from ..externals.joblib import delayed
|
||||
from ..isotonic import IsotonicRegression
|
||||
|
|
@ -65,7 +65,7 @@ def _smacof_single(similarities, metric=True, n_components=2, init=None,
|
|||
Number of iterations run.
|
||||
|
||||
"""
|
||||
similarities = ensure_symmetric(similarities, raise_exception=True)
|
||||
similarities = check_symmetric(similarities, raise_exception=True)
|
||||
|
||||
n_samples = similarities.shape[0]
|
||||
random_state = check_random_state(random_state)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from scipy.sparse.linalg import lobpcg
|
|||
|
||||
from ..base import BaseEstimator
|
||||
from ..externals import six
|
||||
from ..utils import check_random_state, check_array, ensure_symmetric
|
||||
from ..utils import check_random_state, check_array, check_symmetric
|
||||
from ..utils.graph import graph_laplacian
|
||||
from ..utils.sparsetools import connected_components
|
||||
from ..utils.arpack import eigsh
|
||||
|
|
@ -183,7 +183,7 @@ def spectral_embedding(adjacency, n_components=8, eigen_solver=None,
|
|||
Andrew V. Knyazev
|
||||
http://dx.doi.org/10.1137%2FS1064827500366124
|
||||
"""
|
||||
adjacency = ensure_symmetric(adjacency)
|
||||
adjacency = check_symmetric(adjacency)
|
||||
|
||||
try:
|
||||
from pyamg import smoothed_aggregation_solver
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from .validation import (as_float_array,
|
|||
assert_all_finite, warn_if_not_float,
|
||||
check_random_state, column_or_1d, check_array,
|
||||
check_consistent_length, check_X_y, indexable,
|
||||
ensure_symmetric)
|
||||
check_symmetric)
|
||||
from .class_weight import compute_class_weight
|
||||
from ..externals.joblib import cpu_count
|
||||
|
||||
|
|
|
|||
|
|
@ -406,16 +406,16 @@ def has_fit_parameter(estimator, parameter):
|
|||
return parameter in getargspec(estimator.fit)[0]
|
||||
|
||||
|
||||
def ensure_symmetric(array, tol=1E-10, raise_warning=True,
|
||||
raise_exception=False):
|
||||
def check_symmetric(array, tol=1E-10, raise_warning=True,
|
||||
raise_exception=False):
|
||||
"""
|
||||
Ensure that the array is symmetric two-dimensional array or sparse matrix,
|
||||
Check that the array is symmetric two-dimensional array or sparse matrix,
|
||||
returning a symmetrized version and optionally raising a warning or
|
||||
exception if the input is not symmetric.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
array : object
|
||||
array : nd-array or sparse matrix
|
||||
Input object to check / convert
|
||||
tol : float
|
||||
Absolute tolerance for equivalence of arrays. Default = 1E-10.
|
||||
|
|
@ -427,7 +427,9 @@ def ensure_symmetric(array, tol=1E-10, raise_warning=True,
|
|||
Returns
|
||||
-------
|
||||
array_sym : object
|
||||
Symmetrized version of the input array
|
||||
Symmetrized version of the input array, i.e. the average of array
|
||||
and array.transpose(). If sparse, then duplicate entries are first
|
||||
summed and zeros are eliminated.
|
||||
"""
|
||||
if (array.ndim != 2) or (array.shape[0] != array.shape[1]):
|
||||
raise ValueError("array must be 2-dimensional and symmetric")
|
||||
|
|
@ -444,6 +446,10 @@ def ensure_symmetric(array, tol=1E-10, raise_warning=True,
|
|||
if raise_warning:
|
||||
warnings.warn("Array is not symmetric, and will be converted "
|
||||
"to symmetric by average with its transpose.")
|
||||
array = 0.5 * (array + array.T)
|
||||
if sp.issparse(array):
|
||||
conversion = 'to' + array.format
|
||||
array = getattr(0.5 * (array + array.T), conversion)()
|
||||
else:
|
||||
array = 0.5 * (array + array.T)
|
||||
|
||||
return array
|
||||
|
|
|
|||
Loading…
Reference in New Issue