Benchmarks for decomposition

RandomizedPCA-arcene

Benchmark setup

from sklearn.decomposition import RandomizedPCA
from deps import load_data

kwargs = {'n_components': 9}
X, y, X_t, y_t = load_data('arcene')
obj = RandomizedPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/RandomizedPCA-arcene-step0-timing.png

Memory usage

_images/RandomizedPCA-arcene-step0-memory.png

Additional output

cProfile

         208 function calls in 0.261 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.261    0.261 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.261    0.261 <f>:1(<module>)
     1    0.003    0.003    0.261    0.261 /tmp/vb_sklearn/sklearn/decomposition/pca.py:442(fit)
     1    0.000    0.000    0.249    0.249 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
     9    0.223    0.025    0.223    0.025 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.218    0.218 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
     8    0.000    0.000    0.218    0.027 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.000    0.000    0.023    0.023 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.016    0.016    0.022    0.022 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     2    0.005    0.003    0.006    0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.005    0.005 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.005    0.005    0.005    0.005 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.004    0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.004    0.004    0.004    0.004 {method 'mean' of 'numpy.ndarray' objects}
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     4    0.001    0.000    0.001    0.000 {method 'any' of 'numpy.ndarray' objects}
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
    38    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
    22    0.000    0.000    0.000    0.000 {isinstance}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     4    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     3    0.000    0.000    0.000    0.000 {hasattr}
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     5    0.000    0.000    0.000    0.000 {getattr}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 {range}
     9    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358                                                   if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360                                                       return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 442
Total time: 0.252881 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   442                                               def fit(self, X, y=None):
   443                                                   """Fit the model to the data X.
   444
   445                                                   Parameters
   446                                                   ----------
   447                                                   X: array-like or scipy.sparse matrix, shape (n_samples, n_features)
   448                                                       Training vector, where n_samples in the number of samples and
   449                                                       n_features is the number of features.
   450
   451                                                   Returns
   452                                                   -------
   453                                                   self : object
   454                                                       Returns the instance itself.
   455                                                   """
   456         1           13     13.0      0.0          self.random_state = check_random_state(self.random_state)
   457         1            9      9.0      0.0          if not hasattr(X, 'todense'):
   458                                                       # not a sparse matrix, ensure this is a 2D array
   459         1         2354   2354.0      0.9              X = np.atleast_2d(as_float_array(X, copy=self.copy))
   460
   461         1            4      4.0      0.0          n_samples = X.shape[0]
   462
   463         1           11     11.0      0.0          if not hasattr(X, 'todense'):
   464                                                       # Center data
   465         1         3955   3955.0      1.6              self.mean_ = np.mean(X, axis=0)
   466         1         2755   2755.0      1.1              X -= self.mean_
   467         1            5      5.0      0.0          if self.n_components is None:
   468                                                       n_components = X.shape[1]
   469                                                   else:
   470         1            3      3.0      0.0              n_components = self.n_components
   471
   472         1            3      3.0      0.0          U, S, V = randomized_svd(X, n_components,
   473         1            2      2.0      0.0                                   n_iterations=self.iterated_power,
   474         1       243685 243685.0     96.4                                   random_state=self.random_state)
   475
   476         1           43     43.0      0.0          self.explained_variance_ = exp_var = (S ** 2) / n_samples
   477         1           29     29.0      0.0          self.explained_variance_ratio_ = exp_var / exp_var.sum()
   478
   479         1            4      4.0      0.0          if self.whiten:
   480                                                       n = X.shape[0]
   481                                                       self.components_ = V / S[:, np.newaxis] * np.sqrt(n)
   482                                                   else:
   483         1            3      3.0      0.0              self.components_ = V
   484
   485         1            3      3.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/RandomizedPCA-arcene-step1-timing.png

Memory usage

_images/RandomizedPCA-arcene-step1-memory.png

Additional output

cProfile

         224 function calls in 0.273 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.273    0.273 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.273    0.273 <f>:1(<module>)
     1    0.000    0.000    0.273    0.273 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     1    0.003    0.003    0.254    0.254 /tmp/vb_sklearn/sklearn/decomposition/pca.py:442(fit)
     1    0.000    0.000    0.244    0.244 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
    10    0.236    0.024    0.236    0.024 {numpy.core._dotblas.dot}
     9    0.000    0.000    0.231    0.026 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.000    0.000    0.214    0.214 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
     1    0.000    0.000    0.022    0.022 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.016    0.016    0.022    0.022 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     1    0.004    0.004    0.020    0.020 /tmp/vb_sklearn/sklearn/decomposition/pca.py:487(transform)
     2    0.005    0.003    0.006    0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.004    0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.004    0.004    0.004    0.004 {method 'mean' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.002    0.002    0.002    0.002 {method 'copy' of 'numpy.ndarray' objects}
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     4    0.001    0.000    0.001    0.000 {method 'any' of 'numpy.ndarray' objects}
    18    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
    18    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
    42    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
    26    0.000    0.000    0.000    0.000 {isinstance}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     4    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     5    0.000    0.000    0.000    0.000 {getattr}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     3    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 {range}
     9    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     8    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0.31821 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358         1            3      3.0      0.0          if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360         1       318207 318207.0    100.0              return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 442
Total time: 0.558864 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   442                                               def fit(self, X, y=None):
   443                                                   """Fit the model to the data X.
   444
   445                                                   Parameters
   446                                                   ----------
   447                                                   X: array-like or scipy.sparse matrix, shape (n_samples, n_features)
   448                                                       Training vector, where n_samples in the number of samples and
   449                                                       n_features is the number of features.
   450
   451                                                   Returns
   452                                                   -------
   453                                                   self : object
   454                                                       Returns the instance itself.
   455                                                   """
   456         2           30     15.0      0.0          self.random_state = check_random_state(self.random_state)
   457         2           16      8.0      0.0          if not hasattr(X, 'todense'):
   458                                                       # not a sparse matrix, ensure this is a 2D array
   459         2         4769   2384.5      0.9              X = np.atleast_2d(as_float_array(X, copy=self.copy))
   460
   461         2           10      5.0      0.0          n_samples = X.shape[0]
   462
   463         2           23     11.5      0.0          if not hasattr(X, 'todense'):
   464                                                       # Center data
   465         2         7848   3924.0      1.4              self.mean_ = np.mean(X, axis=0)
   466         2         5519   2759.5      1.0              X -= self.mean_
   467         2           11      5.5      0.0          if self.n_components is None:
   468                                                       n_components = X.shape[1]
   469                                                   else:
   470         2            6      3.0      0.0              n_components = self.n_components
   471
   472         2            6      3.0      0.0          U, S, V = randomized_svd(X, n_components,
   473         2            6      3.0      0.0                                   n_iterations=self.iterated_power,
   474         2       540482 270241.0     96.7                                   random_state=self.random_state)
   475
   476         2           73     36.5      0.0          self.explained_variance_ = exp_var = (S ** 2) / n_samples
   477         2           47     23.5      0.0          self.explained_variance_ratio_ = exp_var / exp_var.sum()
   478
   479         2            6      3.0      0.0          if self.whiten:
   480                                                       n = X.shape[0]
   481                                                       self.components_ = V / S[:, np.newaxis] * np.sqrt(n)
   482                                                   else:
   483         2            7      3.5      0.0              self.components_ = V
   484
   485         2            5      2.5      0.0          return self

RandomizedPCA-madelon

Benchmark setup

from sklearn.decomposition import RandomizedPCA
from deps import load_data

kwargs = {'n_components': 9}
X, y, X_t, y_t = load_data('madelon')
obj = RandomizedPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/RandomizedPCA-madelon-step0-timing.png

Memory usage

_images/RandomizedPCA-madelon-step0-memory.png

Additional output

cProfile

         208 function calls in 0.408 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.408    0.408 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.408    0.408 <f>:1(<module>)
     1    0.004    0.004    0.408    0.408 /tmp/vb_sklearn/sklearn/decomposition/pca.py:442(fit)
     1    0.000    0.000    0.368    0.368 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
     8    0.000    0.000    0.349    0.044 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     9    0.349    0.039    0.349    0.039 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.310    0.310 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
     1    0.000    0.000    0.030    0.030 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.030    0.030    0.030    0.030 {method 'mean' of 'numpy.ndarray' objects}
     1    0.008    0.008    0.009    0.009 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.006    0.006    0.006    0.006 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.005    0.005 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.005    0.005    0.005    0.005 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.001    0.001    0.002    0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     2    0.001    0.001    0.002    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     4    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
    38    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
    22    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     4    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     3    0.000    0.000    0.000    0.000 {hasattr}
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     5    0.000    0.000    0.000    0.000 {getattr}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 {range}
     9    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358                                                   if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360                                                       return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 442
Total time: 0.472908 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   442                                               def fit(self, X, y=None):
   443                                                   """Fit the model to the data X.
   444
   445                                                   Parameters
   446                                                   ----------
   447                                                   X: array-like or scipy.sparse matrix, shape (n_samples, n_features)
   448                                                       Training vector, where n_samples in the number of samples and
   449                                                       n_features is the number of features.
   450
   451                                                   Returns
   452                                                   -------
   453                                                   self : object
   454                                                       Returns the instance itself.
   455                                                   """
   456         1           13     13.0      0.0          self.random_state = check_random_state(self.random_state)
   457         1            8      8.0      0.0          if not hasattr(X, 'todense'):
   458                                                       # not a sparse matrix, ensure this is a 2D array
   459         1         2254   2254.0      0.5              X = np.atleast_2d(as_float_array(X, copy=self.copy))
   460
   461         1            5      5.0      0.0          n_samples = X.shape[0]
   462
   463         1           12     12.0      0.0          if not hasattr(X, 'todense'):
   464                                                       # Center data
   465         1        42491  42491.0      9.0              self.mean_ = np.mean(X, axis=0)
   466         1         3599   3599.0      0.8              X -= self.mean_
   467         1            5      5.0      0.0          if self.n_components is None:
   468                                                       n_components = X.shape[1]
   469                                                   else:
   470         1            2      2.0      0.0              n_components = self.n_components
   471
   472         1            4      4.0      0.0          U, S, V = randomized_svd(X, n_components,
   473         1            3      3.0      0.0                                   n_iterations=self.iterated_power,
   474         1       424436 424436.0     89.8                                   random_state=self.random_state)
   475
   476         1           40     40.0      0.0          self.explained_variance_ = exp_var = (S ** 2) / n_samples
   477         1           28     28.0      0.0          self.explained_variance_ratio_ = exp_var / exp_var.sum()
   478
   479         1            3      3.0      0.0          if self.whiten:
   480                                                       n = X.shape[0]
   481                                                       self.components_ = V / S[:, np.newaxis] * np.sqrt(n)
   482                                                   else:
   483         1            3      3.0      0.0              self.components_ = V
   484
   485         1            2      2.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/RandomizedPCA-madelon-step1-timing.png

Memory usage

_images/RandomizedPCA-madelon-step1-memory.png

Additional output

cProfile

         224 function calls in 0.427 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.427    0.427 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.427    0.427 <f>:1(<module>)
     1    0.000    0.000    0.427    0.427 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     1    0.004    0.004    0.408    0.408 /tmp/vb_sklearn/sklearn/decomposition/pca.py:442(fit)
     1    0.000    0.000    0.371    0.371 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
     9    0.000    0.000    0.368    0.041 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
    10    0.368    0.037    0.368    0.037 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.303    0.303 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
     1    0.000    0.000    0.030    0.030 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.030    0.030    0.030    0.030 {method 'mean' of 'numpy.ndarray' objects}
     1    0.004    0.004    0.020    0.020 /tmp/vb_sklearn/sklearn/decomposition/pca.py:487(transform)
     1    0.008    0.008    0.009    0.009 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.006    0.006    0.006    0.006 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.002    0.002    0.002    0.002 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.001    0.001    0.002    0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     2    0.001    0.001    0.002    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
    18    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
    18    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     4    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
    42    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
    26    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     4    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     5    0.000    0.000    0.000    0.000 {getattr}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     3    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     4    0.000    0.000    0.000    0.000 {range}
     8    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     9    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0.516149 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358         1            3      3.0      0.0          if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360         1       516146 516146.0    100.0              return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 442
Total time: 0.95637 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   442                                               def fit(self, X, y=None):
   443                                                   """Fit the model to the data X.
   444
   445                                                   Parameters
   446                                                   ----------
   447                                                   X: array-like or scipy.sparse matrix, shape (n_samples, n_features)
   448                                                       Training vector, where n_samples in the number of samples and
   449                                                       n_features is the number of features.
   450
   451                                                   Returns
   452                                                   -------
   453                                                   self : object
   454                                                       Returns the instance itself.
   455                                                   """
   456         2           31     15.5      0.0          self.random_state = check_random_state(self.random_state)
   457         2           16      8.0      0.0          if not hasattr(X, 'todense'):
   458                                                       # not a sparse matrix, ensure this is a 2D array
   459         2         4657   2328.5      0.5              X = np.atleast_2d(as_float_array(X, copy=self.copy))
   460
   461         2           12      6.0      0.0          n_samples = X.shape[0]
   462
   463         2           24     12.0      0.0          if not hasattr(X, 'todense'):
   464                                                       # Center data
   465         2        85613  42806.5      9.0              self.mean_ = np.mean(X, axis=0)
   466         2         7183   3591.5      0.8              X -= self.mean_
   467         2           12      6.0      0.0          if self.n_components is None:
   468                                                       n_components = X.shape[1]
   469                                                   else:
   470         2            4      2.0      0.0              n_components = self.n_components
   471
   472         2            7      3.5      0.0          U, S, V = randomized_svd(X, n_components,
   473         2            8      4.0      0.0                                   n_iterations=self.iterated_power,
   474         2       858645 429322.5     89.8                                   random_state=self.random_state)
   475
   476         2           83     41.5      0.0          self.explained_variance_ = exp_var = (S ** 2) / n_samples
   477         2           56     28.0      0.0          self.explained_variance_ratio_ = exp_var / exp_var.sum()
   478
   479         2            6      3.0      0.0          if self.whiten:
   480                                                       n = X.shape[0]
   481                                                       self.components_ = V / S[:, np.newaxis] * np.sqrt(n)
   482                                                   else:
   483         2            8      4.0      0.0              self.components_ = V
   484
   485         2            5      2.5      0.0          return self

ProbabilisticPCA-minimadelon

Benchmark setup

from sklearn.decomposition import ProbabilisticPCA
from deps import load_data

kwargs = {'n_components': 9}
X, y, X_t, y_t = load_data('minimadelon')
obj = ProbabilisticPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/ProbabilisticPCA-minimadelon-step0-timing.png

Memory usage

_images/ProbabilisticPCA-minimadelon-step0-memory.png

Additional output

cProfile

         127 function calls in 0.035 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.035    0.035 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.035    0.035 <f>:1(<module>)
     1    0.014    0.014    0.035    0.035 /tmp/vb_sklearn/sklearn/decomposition/pca.py:307(fit)
     9    0.012    0.001    0.013    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:740(outer)
     1    0.000    0.000    0.007    0.007 /tmp/vb_sklearn/sklearn/decomposition/pca.py:179(fit)
     1    0.000    0.000    0.007    0.007 /tmp/vb_sklearn/sklearn/decomposition/pca.py:222(_fit)
     1    0.005    0.005    0.006    0.006 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
     1    0.001    0.001    0.001    0.001 {numpy.core.multiarray.zeros}
     2    0.001    0.000    0.001    0.000 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
    18    0.000    0.000    0.000    0.000 {method 'ravel' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}
    21    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
    22    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.empty}
     1    0.000    0.000    0.000    0.000 {method 'fill' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {getattr}
     2    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     3    0.000    0.000    0.000    0.000 {isinstance}
     2    0.000    0.000    0.000    0.000 {issubclass}
     6    0.000    0.000    0.000    0.000 {len}
     3    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {abs}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit_transform at line 196
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   196                                               def fit_transform(self, X, y=None, **params):
   197                                                   """Fit the model with X and apply the dimensionality reduction on X.
   198
   199                                                   Parameters
   200                                                   ----------
   201                                                   X : array-like, shape (n_samples, n_features)
   202                                                       Training data, where n_samples in the number of samples
   203                                                       and n_features is the number of features.
   204
   205                                                   Returns
   206                                                   -------
   207                                                   X_new : array-like, shape (n_samples, n_components)
   208
   209                                                   """
   210                                                   U, S, V = self._fit(X, **params)
   211                                                   U = U[:, :self.n_components]
   212
   213                                                   if self.whiten:
   214                                                       # X_new = X * V / S * sqrt(n_samples) = U * sqrt(n_samples)
   215                                                       U *= np.sqrt(X.shape[0])
   216                                                   else:
   217                                                       # X_new = X * V = U * S * V^T * V = U * S
   218                                                       U *= S[:self.n_components]
   219
   220                                                   return U

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 307
Total time: 0.032152 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   307                                               def fit(self, X, y=None, homoscedastic=True):
   308                                                   """Additionally to PCA.fit, learns a covariance model
   309
   310                                                   Parameters
   311                                                   ----------
   312                                                   X : array of shape(n_samples, n_dim)
   313                                                       The data to fit
   314
   315                                                   homoscedastic : bool, optional,
   316                                                       If True, average variance across remaining dimensions
   317                                                   """
   318         1         6020   6020.0     18.7          PCA.fit(self, X)
   319         1            4      4.0      0.0          self.dim = X.shape[1]
   320         1           82     82.0      0.3          Xr = X - self.mean_
   321         1          835    835.0      2.6          Xr -= np.dot(np.dot(Xr, self.components_.T), self.components_)
   322         1            5      5.0      0.0          n_samples = X.shape[0]
   323         1            3      3.0      0.0          if self.dim <= self.n_components:
   324                                                       delta = np.zeros(self.dim)
   325         1            2      2.0      0.0          elif homoscedastic:
   326                                                       delta = (Xr ** 2).sum() * np.ones(self.dim) \
   327         1          174    174.0      0.5                      / (n_samples * self.dim)
   328                                                   else:
   329                                                       delta = (Xr ** 2).mean(0) / (self.dim - self.n_components)
   330         1          360    360.0      1.1          self.covariance_ = np.diag(delta)
   331        10           42      4.2      0.1          for k in range(self.n_components):
   332         9        11868   1318.7     36.9              add_cov = np.outer(self.components_[k], self.components_[k])
   333         9        12755   1417.2     39.7              self.covariance_ += self.explained_variance_[k] * add_cov
   334         1            2      2.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/ProbabilisticPCA-minimadelon-step1-timing.png

Memory usage

_images/ProbabilisticPCA-minimadelon-step1-memory.png

Additional output

cProfile

         50 function calls in 0.006 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.006    0.006 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.006    0.006 <f>:1(<module>)
     1    0.000    0.000    0.006    0.006 /tmp/vb_sklearn/sklearn/decomposition/pca.py:196(fit_transform)
     1    0.000    0.000    0.006    0.006 /tmp/vb_sklearn/sklearn/decomposition/pca.py:222(_fit)
     1    0.005    0.005    0.006    0.006 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.000    0.000 {getattr}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     3    0.000    0.000    0.000    0.000 {isinstance}
     3    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     2    0.000    0.000    0.000    0.000 {issubclass}
     5    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit_transform at line 196
Total time: 0.006064 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   196                                               def fit_transform(self, X, y=None, **params):
   197                                                   """Fit the model with X and apply the dimensionality reduction on X.
   198
   199                                                   Parameters
   200                                                   ----------
   201                                                   X : array-like, shape (n_samples, n_features)
   202                                                       Training data, where n_samples in the number of samples
   203                                                       and n_features is the number of features.
   204
   205                                                   Returns
   206                                                   -------
   207                                                   X_new : array-like, shape (n_samples, n_components)
   208
   209                                                   """
   210         1         6030   6030.0     99.4          U, S, V = self._fit(X, **params)
   211         1            6      6.0      0.1          U = U[:, :self.n_components]
   212
   213         1            2      2.0      0.0          if self.whiten:
   214                                                       # X_new = X * V / S * sqrt(n_samples) = U * sqrt(n_samples)
   215                                                       U *= np.sqrt(X.shape[0])
   216                                                   else:
   217                                                       # X_new = X * V = U * S * V^T * V = U * S
   218         1           24     24.0      0.4              U *= S[:self.n_components]
   219
   220         1            2      2.0      0.0          return U

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 307
Total time: 0.032152 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   307                                               def fit(self, X, y=None, homoscedastic=True):
   308                                                   """Additionally to PCA.fit, learns a covariance model
   309
   310                                                   Parameters
   311                                                   ----------
   312                                                   X : array of shape(n_samples, n_dim)
   313                                                       The data to fit
   314
   315                                                   homoscedastic : bool, optional,
   316                                                       If True, average variance across remaining dimensions
   317                                                   """
   318         1         6020   6020.0     18.7          PCA.fit(self, X)
   319         1            4      4.0      0.0          self.dim = X.shape[1]
   320         1           82     82.0      0.3          Xr = X - self.mean_
   321         1          835    835.0      2.6          Xr -= np.dot(np.dot(Xr, self.components_.T), self.components_)
   322         1            5      5.0      0.0          n_samples = X.shape[0]
   323         1            3      3.0      0.0          if self.dim <= self.n_components:
   324                                                       delta = np.zeros(self.dim)
   325         1            2      2.0      0.0          elif homoscedastic:
   326                                                       delta = (Xr ** 2).sum() * np.ones(self.dim) \
   327         1          174    174.0      0.5                      / (n_samples * self.dim)
   328                                                   else:
   329                                                       delta = (Xr ** 2).mean(0) / (self.dim - self.n_components)
   330         1          360    360.0      1.1          self.covariance_ = np.diag(delta)
   331        10           42      4.2      0.1          for k in range(self.n_components):
   332         9        11868   1318.7     36.9              add_cov = np.outer(self.components_[k], self.components_[k])
   333         9        12755   1417.2     39.7              self.covariance_ += self.explained_variance_[k] * add_cov
   334         1            2      2.0      0.0          return self

ProbabilisticPCA-madelon

Benchmark setup

from sklearn.decomposition import ProbabilisticPCA
from deps import load_data

kwargs = {'n_components': 9}
X, y, X_t, y_t = load_data('madelon')
obj = ProbabilisticPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/ProbabilisticPCA-madelon-step0-timing.png

Memory usage

_images/ProbabilisticPCA-madelon-step0-memory.png

Additional output

cProfile

         127 function calls in 2.360 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    2.360    2.360 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    2.360    2.360 <f>:1(<module>)
     1    0.036    0.036    2.360    2.360 /tmp/vb_sklearn/sklearn/decomposition/pca.py:307(fit)
     1    0.000    0.000    2.265    2.265 /tmp/vb_sklearn/sklearn/decomposition/pca.py:179(fit)
     1    0.004    0.004    2.265    2.265 /tmp/vb_sklearn/sklearn/decomposition/pca.py:222(_fit)
     1    2.191    2.191    2.223    2.223 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     2    0.044    0.022    0.044    0.022 {numpy.core._dotblas.dot}
     1    0.029    0.029    0.032    0.032 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.031    0.031 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.031    0.031    0.031    0.031 {method 'mean' of 'numpy.ndarray' objects}
     9    0.012    0.001    0.012    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:740(outer)
     1    0.000    0.000    0.007    0.007 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.007    0.007    0.007    0.007 {method 'copy' of 'numpy.ndarray' objects}
     2    0.003    0.002    0.003    0.002 {method 'any' of 'numpy.ndarray' objects}
     2    0.003    0.001    0.003    0.001 {method 'sum' of 'numpy.ndarray' objects}
    18    0.000    0.000    0.000    0.000 {method 'ravel' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
     1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
    21    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
    22    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 {getattr}
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.empty}
     1    0.000    0.000    0.000    0.000 {method 'fill' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {range}
     3    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     2    0.000    0.000    0.000    0.000 {issubclass}
     6    0.000    0.000    0.000    0.000 {len}
     3    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {abs}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit_transform at line 196
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   196                                               def fit_transform(self, X, y=None, **params):
   197                                                   """Fit the model with X and apply the dimensionality reduction on X.
   198
   199                                                   Parameters
   200                                                   ----------
   201                                                   X : array-like, shape (n_samples, n_features)
   202                                                       Training data, where n_samples in the number of samples
   203                                                       and n_features is the number of features.
   204
   205                                                   Returns
   206                                                   -------
   207                                                   X_new : array-like, shape (n_samples, n_components)
   208
   209                                                   """
   210                                                   U, S, V = self._fit(X, **params)
   211                                                   U = U[:, :self.n_components]
   212
   213                                                   if self.whiten:
   214                                                       # X_new = X * V / S * sqrt(n_samples) = U * sqrt(n_samples)
   215                                                       U *= np.sqrt(X.shape[0])
   216                                                   else:
   217                                                       # X_new = X * V = U * S * V^T * V = U * S
   218                                                       U *= S[:self.n_components]
   219
   220                                                   return U

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 307
Total time: 2.37672 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   307                                               def fit(self, X, y=None, homoscedastic=True):
   308                                                   """Additionally to PCA.fit, learns a covariance model
   309
   310                                                   Parameters
   311                                                   ----------
   312                                                   X : array of shape(n_samples, n_dim)
   313                                                       The data to fit
   314
   315                                                   homoscedastic : bool, optional,
   316                                                       If True, average variance across remaining dimensions
   317                                                   """
   318         1      2281819 2281819.0     96.0          PCA.fit(self, X)
   319         1            7      7.0      0.0          self.dim = X.shape[1]
   320         1         4123   4123.0      0.2          Xr = X - self.mean_
   321         1        46195  46195.0      1.9          Xr -= np.dot(np.dot(Xr, self.components_.T), self.components_)
   322         1            8      8.0      0.0          n_samples = X.shape[0]
   323         1            4      4.0      0.0          if self.dim <= self.n_components:
   324                                                       delta = np.zeros(self.dim)
   325         1            3      3.0      0.0          elif homoscedastic:
   326                                                       delta = (Xr ** 2).sum() * np.ones(self.dim) \
   327         1         5858   5858.0      0.2                      / (n_samples * self.dim)
   328                                                   else:
   329                                                       delta = (Xr ** 2).mean(0) / (self.dim - self.n_components)
   330         1          433    433.0      0.0          self.covariance_ = np.diag(delta)
   331        10           50      5.0      0.0          for k in range(self.n_components):
   332         9        25482   2831.3      1.1              add_cov = np.outer(self.components_[k], self.components_[k])
   333         9        12737   1415.2      0.5              self.covariance_ += self.explained_variance_[k] * add_cov
   334         1            3      3.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/ProbabilisticPCA-madelon-step1-timing.png

Memory usage

_images/ProbabilisticPCA-madelon-step1-memory.png

Additional output

cProfile

         50 function calls in 2.309 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    2.309    2.309 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    2.309    2.309 <f>:1(<module>)
     1    0.000    0.000    2.309    2.309 /tmp/vb_sklearn/sklearn/decomposition/pca.py:196(fit_transform)
     1    0.004    0.004    2.309    2.309 /tmp/vb_sklearn/sklearn/decomposition/pca.py:222(_fit)
     1    2.230    2.230    2.273    2.273 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.039    0.039    0.043    0.043 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.030    0.030 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2299(mean)
     1    0.030    0.030    0.030    0.030 {method 'mean' of 'numpy.ndarray' objects}
     2    0.003    0.002    0.003    0.002 {method 'any' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
     1    0.002    0.002    0.002    0.002 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     3    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 {getattr}
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.000    0.000 {issubclass}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     3    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     5    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {range}
     3    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit_transform at line 196
Total time: 2.29853 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   196                                               def fit_transform(self, X, y=None, **params):
   197                                                   """Fit the model with X and apply the dimensionality reduction on X.
   198
   199                                                   Parameters
   200                                                   ----------
   201                                                   X : array-like, shape (n_samples, n_features)
   202                                                       Training data, where n_samples in the number of samples
   203                                                       and n_features is the number of features.
   204
   205                                                   Returns
   206                                                   -------
   207                                                   X_new : array-like, shape (n_samples, n_components)
   208
   209                                                   """
   210         1      2298414 2298414.0    100.0          U, S, V = self._fit(X, **params)
   211         1            7      7.0      0.0          U = U[:, :self.n_components]
   212
   213         1            2      2.0      0.0          if self.whiten:
   214                                                       # X_new = X * V / S * sqrt(n_samples) = U * sqrt(n_samples)
   215                                                       U *= np.sqrt(X.shape[0])
   216                                                   else:
   217                                                       # X_new = X * V = U * S * V^T * V = U * S
   218         1          102    102.0      0.0              U *= S[:self.n_components]
   219
   220         1            3      3.0      0.0          return U

File: /tmp/vb_sklearn/sklearn/decomposition/pca.py
Function: fit at line 307
Total time: 2.37672 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   307                                               def fit(self, X, y=None, homoscedastic=True):
   308                                                   """Additionally to PCA.fit, learns a covariance model
   309
   310                                                   Parameters
   311                                                   ----------
   312                                                   X : array of shape(n_samples, n_dim)
   313                                                       The data to fit
   314
   315                                                   homoscedastic : bool, optional,
   316                                                       If True, average variance across remaining dimensions
   317                                                   """
   318         1      2281819 2281819.0     96.0          PCA.fit(self, X)
   319         1            7      7.0      0.0          self.dim = X.shape[1]
   320         1         4123   4123.0      0.2          Xr = X - self.mean_
   321         1        46195  46195.0      1.9          Xr -= np.dot(np.dot(Xr, self.components_.T), self.components_)
   322         1            8      8.0      0.0          n_samples = X.shape[0]
   323         1            4      4.0      0.0          if self.dim <= self.n_components:
   324                                                       delta = np.zeros(self.dim)
   325         1            3      3.0      0.0          elif homoscedastic:
   326                                                       delta = (Xr ** 2).sum() * np.ones(self.dim) \
   327         1         5858   5858.0      0.2                      / (n_samples * self.dim)
   328                                                   else:
   329                                                       delta = (Xr ** 2).mean(0) / (self.dim - self.n_components)
   330         1          433    433.0      0.0          self.covariance_ = np.diag(delta)
   331        10           50      5.0      0.0          for k in range(self.n_components):
   332         9        25482   2831.3      1.1              add_cov = np.outer(self.components_[k], self.components_[k])
   333         9        12737   1415.2      0.5              self.covariance_ += self.explained_variance_[k] * add_cov
   334         1            3      3.0      0.0          return self

KernelPCA-rbf-minimadelon

Benchmark setup

from sklearn.decomposition import KernelPCA
from deps import load_data

kwargs = {'kernel': 'rbf', 'n_components': 9}
X, y, X_t, y_t = load_data('minimadelon')
obj = KernelPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/KernelPCA-rbf-minimadelon-step0-timing.png

Memory usage

_images/KernelPCA-rbf-minimadelon-step0-memory.png

Additional output

cProfile

         143 function calls in 0.004 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.004    0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.004    0.004 <f>:1(<module>)
     1    0.000    0.000    0.004    0.004 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:165(fit)
     1    0.000    0.000    0.004    0.004 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:114(_fit_transform)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:325(rbf_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:101(euclidean_distances)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     2    0.000    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     1    0.001    0.001    0.001    0.001 {numpy.core._dotblas.dot}
     8    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:850(fit)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     6    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
    20    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     8    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
    12    0.000    0.000    0.000    0.000 {isinstance}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
     1    0.000    0.000    0.000    0.000 {method 'argsort' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     2    0.000    0.000    0.000    0.000 {getattr}
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
    12    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     4    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     3    0.000    0.000    0.000    0.000 {issubclass}
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.00301 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         1         3005   3005.0     99.8          self._fit_transform(X)
   180
   181         1            3      3.0      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         1            2      2.0      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201                                                   self.fit(X, **params)
   202
   203                                                   X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205                                                   if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208                                                   return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221                                                   K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222                                                   return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

Benchmark statement

obj.transform(X)

Execution time

_images/KernelPCA-rbf-minimadelon-step1-timing.png

Memory usage

_images/KernelPCA-rbf-minimadelon-step1-memory.png

Additional output

cProfile

         108 function calls in 0.002 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.002    0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.002    0.002 <f>:1(<module>)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:210(transform)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:325(rbf_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:101(euclidean_distances)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     2    0.001    0.000    0.001    0.000 {numpy.core._dotblas.dot}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     6    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
    18    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
    11    0.000    0.000    0.000    0.000 {isinstance}
     6    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
    10    0.000    0.000    0.000    0.000 {len}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     2    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.00301 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         1         3005   3005.0     99.8          self._fit_transform(X)
   180
   181         1            3      3.0      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         1            2      2.0      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201                                                   self.fit(X, **params)
   202
   203                                                   X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205                                                   if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208                                                   return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0.001739 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221         1         1675   1675.0     96.3          K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222         1           64     64.0      3.7          return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

Benchmark statement

obj.fit_transform(X)

Execution time

_images/KernelPCA-rbf-minimadelon-step2-timing.png

Memory usage

_images/KernelPCA-rbf-minimadelon-step2-memory.png

Additional output

cProfile

         144 function calls in 0.003 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.003    0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.003    0.003 <f>:1(<module>)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:188(fit_transform)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:165(fit)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:114(_fit_transform)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:325(rbf_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:101(euclidean_distances)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.001    0.001    0.001    0.001 {numpy.core._dotblas.dot}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     8    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     9    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:850(fit)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     6    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     8    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
    20    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
    12    0.000    0.000    0.000    0.000 {isinstance}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
     1    0.000    0.000    0.000    0.000 {method 'argsort' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {getattr}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 {issubclass}
    12    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     4    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.005915 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         2         5905   2952.5     99.8          self._fit_transform(X)
   180
   181         2            6      3.0      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         2            4      2.0      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0.002953 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201         1         2920   2920.0     98.9          self.fit(X, **params)
   202
   203         1           30     30.0      1.0          X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205         1            2      2.0      0.1          if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208         1            1      1.0      0.0          return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0.001739 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221         1         1675   1675.0     96.3          K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222         1           64     64.0      3.7          return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

KernelPCA-sigmoid-minimadelon

Benchmark setup

from sklearn.decomposition import KernelPCA
from deps import load_data

kwargs = {'kernel': 'sigmoid', 'n_components': 9}
X, y, X_t, y_t = load_data('minimadelon')
obj = KernelPCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/KernelPCA-sigmoid-minimadelon-step0-timing.png

Memory usage

_images/KernelPCA-sigmoid-minimadelon-step0-memory.png

Additional output

cProfile

         136 function calls in 0.003 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.003    0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.003    0.003 <f>:1(<module>)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:165(fit)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:114(_fit_transform)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:296(sigmoid_kernel)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:249(linear_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.001    0.001    0.001    0.001 {numpy.core._dotblas.dot}
     2    0.000    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     7    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:850(fit)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     6    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     8    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
    18    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
    10    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 {method 'argsort' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     2    0.000    0.000    0.000    0.000 {getattr}
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
    12    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.002722 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         1         2717   2717.0     99.8          self._fit_transform(X)
   180
   181         1            3      3.0      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         1            2      2.0      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201                                                   self.fit(X, **params)
   202
   203                                                   X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205                                                   if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208                                                   return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221                                                   K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222                                                   return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

Benchmark statement

obj.transform(X)

Execution time

_images/KernelPCA-sigmoid-minimadelon-step1-timing.png

Memory usage

_images/KernelPCA-sigmoid-minimadelon-step1-memory.png

Additional output

cProfile

         101 function calls in 0.001 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.001    0.001 <f>:1(<module>)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:210(transform)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:296(sigmoid_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:249(linear_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     2    0.001    0.000    0.001    0.000 {numpy.core._dotblas.dot}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     5    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
    16    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     6    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     9    0.000    0.000    0.000    0.000 {isinstance}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
    10    0.000    0.000    0.000    0.000 {len}
     2    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.002722 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         1         2717   2717.0     99.8          self._fit_transform(X)
   180
   181         1            3      3.0      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         1            2      2.0      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201                                                   self.fit(X, **params)
   202
   203                                                   X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205                                                   if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208                                                   return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0.001518 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221         1         1455   1455.0     95.8          K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222         1           63     63.0      4.2          return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

Benchmark statement

obj.fit_transform(X)

Execution time

_images/KernelPCA-sigmoid-minimadelon-step2-timing.png

Memory usage

_images/KernelPCA-sigmoid-minimadelon-step2-memory.png

Additional output

cProfile

         137 function calls in 0.003 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.003    0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.003    0.003 <f>:1(<module>)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:188(fit_transform)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:165(fit)
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:114(_fit_transform)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py:102(_get_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:564(pairwise_kernels)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:296(sigmoid_kernel)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:249(linear_kernel)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.001    0.001    0.001    0.001 {numpy.core._dotblas.dot}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:52(check_pairwise_arrays)
     7    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:867(transform)
     8    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/preprocessing.py:850(fit)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     6    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     8    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
    18    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
    10    0.000    0.000    0.000    0.000 {isinstance}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
     1    0.000    0.000    0.000    0.000 {method 'argsort' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/metrics/pairwise.py:630(<genexpr>)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     2    0.000    0.000    0.000    0.000 {getattr}
    12    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     3    0.000    0.000    0.000    0.000 {issubclass}
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit at line 165
Total time: 0.005464 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   165                                               def fit(self, X, y=None):
   166                                                   """Fit the model from data in X.
   167
   168                                                   Parameters
   169                                                   ----------
   170                                                   X: array-like, shape (n_samples, n_features)
   171                                                       Training vector, where n_samples in the number of samples
   172                                                       and n_features is the number of features.
   173
   174                                                   Returns
   175                                                   -------
   176                                                   self : object
   177                                                       Returns the instance itself.
   178                                                   """
   179         2         5454   2727.0     99.8          self._fit_transform(X)
   180
   181         2            7      3.5      0.1          if self.fit_inverse_transform:
   182                                                       sqrt_lambdas = np.diag(np.sqrt(self.lambdas_))
   183                                                       X_transformed = np.dot(self.alphas_, sqrt_lambdas)
   184                                                       self._fit_inverse_transform(X_transformed, X)
   185
   186         2            3      1.5      0.1          return self

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: fit_transform at line 188
Total time: 0.002791 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   188                                               def fit_transform(self, X, y=None, **params):
   189                                                   """Fit the model from data in X and transform X.
   190
   191                                                   Parameters
   192                                                   ----------
   193                                                   X: array-like, shape (n_samples, n_features)
   194                                                       Training vector, where n_samples in the number of samples
   195                                                       and n_features is the number of features.
   196
   197                                                   Returns
   198                                                   -------
   199                                                   X_new: array-like, shape (n_samples, n_components)
   200                                                   """
   201         1         2757   2757.0     98.8          self.fit(X, **params)
   202
   203         1           30     30.0      1.1          X_transformed = self.alphas_ * np.sqrt(self.lambdas_)
   204
   205         1            2      2.0      0.1          if self.fit_inverse_transform:
   206                                                       self._fit_inverse_transform(X_transformed, X)
   207
   208         1            2      2.0      0.1          return X_transformed

File: /tmp/vb_sklearn/sklearn/decomposition/kernel_pca.py
Function: transform at line 210
Total time: 0.001518 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   210                                               def transform(self, X):
   211                                                   """Transform X.
   212
   213                                                   Parameters
   214                                                   ----------
   215                                                   X: array-like, shape (n_samples, n_features)
   216
   217                                                   Returns
   218                                                   -------
   219                                                   X_new: array-like, shape (n_samples, n_components)
   220                                                   """
   221         1         1455   1455.0     95.8          K = self.centerer.transform(self._get_kernel(X, self.X_fit_))
   222         1           63     63.0      4.2          return np.dot(K, self.alphas_ / np.sqrt(self.lambdas_))

FastICA-deflation-blobs

Benchmark setup

from sklearn.decomposition import FastICA
from deps import load_data

kwargs = {'n_components': 9, 'algorithm': 'deflation'}
X, y, X_t, y_t = load_data('blobs')
obj = FastICA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/FastICA-deflation-blobs-step0-timing.png

Memory usage

_images/FastICA-deflation-blobs-step0-memory.png

Additional output

cProfile

         667 function calls in 0.027 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.027    0.027 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.027    0.027 <f>:1(<module>)
     1    0.000    0.000    0.027    0.027 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:389(fit)
     1    0.000    0.000    0.027    0.027 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:130(fastica)
     1    0.007    0.007    0.016    0.016 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:52(_ica_def)
     1    0.009    0.009    0.010    0.010 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
    54    0.004    0.000    0.004    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:229(g)
   109    0.003    0.000    0.003    0.000 {method 'mean' of 'numpy.ndarray' objects}
   166    0.002    0.000    0.002    0.000 {numpy.core._dotblas.dot}
    54    0.001    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:21(_gs_decorrelation)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   117    0.001    0.000    0.001    0.000 {method 'sum' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
    56    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
    55    0.000    0.000    0.000    0.000 {method 'get' of 'dict' objects}
     9    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     3    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
     2    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 {getattr}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     3    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     2    0.000    0.000    0.000    0.000 {issubclass}
     1    0.000    0.000    0.000    0.000 {min}
     5    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 0.031772 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            3      3.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            2      2.0      0.0                          self.algorithm, self.whiten,
   392         1            2      2.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1        31730  31730.0     99.9                          random_state=self.random_state)
   395         1            4      4.0      0.0          if self.whiten == True:
   396         1           24     24.0      0.1              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            3      3.0      0.0          self.sources_ = sources_
   400         1            2      2.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407                                                   return np.dot(X, self.components_.T)

Benchmark statement

obj.transform(X)

Execution time

_images/FastICA-deflation-blobs-step1-timing.png

Memory usage

_images/FastICA-deflation-blobs-step1-memory.png

Additional output

cProfile

         5 function calls in 0.000 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.000    0.000 <f>:1(<module>)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:402(transform)
     1    0.000    0.000    0.000    0.000 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 0.031772 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            3      3.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            2      2.0      0.0                          self.algorithm, self.whiten,
   392         1            2      2.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1        31730  31730.0     99.9                          random_state=self.random_state)
   395         1            4      4.0      0.0          if self.whiten == True:
   396         1           24     24.0      0.1              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            3      3.0      0.0          self.sources_ = sources_
   400         1            2      2.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0.000342 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407         1          342    342.0    100.0          return np.dot(X, self.components_.T)

FastICA-parallel-arcene

Benchmark setup

from sklearn.decomposition import FastICA
from deps import load_data

kwargs = {'n_components': 9, 'algorithm': 'parallel'}
X, y, X_t, y_t = load_data('arcene')
obj = FastICA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/FastICA-parallel-arcene-step0-timing.png

Memory usage

_images/FastICA-parallel-arcene-step0-memory.png

Additional output

cProfile

         6331 function calls in 0.664 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.664    0.664 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.664    0.664 <f>:1(<module>)
     1    0.000    0.000    0.664    0.664 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:389(fit)
     1    0.026    0.026    0.662    0.662 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:130(fastica)
     1    0.482    0.482    0.519    0.519 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.008    0.008    0.083    0.083 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:94(_ica_par)
   840    0.044    0.000    0.044    0.000 {numpy.core._dotblas.dot}
   105    0.004    0.000    0.042    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:40(_sym_decorrelation)
   106    0.030    0.000    0.041    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   105    0.020    0.000    0.031    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
   104    0.015    0.000    0.015    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:229(g)
   212    0.010    0.000    0.010    0.000 {method 'any' of 'numpy.ndarray' objects}
   313    0.005    0.000    0.007    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
   105    0.007    0.000    0.007    0.000 {method 'mean' of 'numpy.ndarray' objects}
   106    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
   525    0.001    0.000    0.003    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
   106    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
   417    0.002    0.000    0.002    0.000 {abs}
   526    0.002    0.000    0.002    0.000 {numpy.core.multiarray.array}
   105    0.000    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
   104    0.001    0.000    0.001    0.000 {max}
   209    0.001    0.000    0.001    0.000 {numpy.core.multiarray.zeros}
   211    0.000    0.000    0.000    0.000 {getattr}
   106    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
   317    0.000    0.000    0.000    0.000 {issubclass}
   214    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
   632    0.000    0.000    0.000    0.000 {len}
   106    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
   106    0.000    0.000    0.000    0.000 {range}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
   213    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
   106    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
   106    0.000    0.000    0.000    0.000 {isinstance}
   106    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
   105    0.000    0.000    0.000    0.000 {method 'get' of 'dict' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 0.565591 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            4      4.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            2      2.0      0.0                          self.algorithm, self.whiten,
   392         1            2      2.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1       564536 564536.0     99.8                          random_state=self.random_state)
   395         1            5      5.0      0.0          if self.whiten == True:
   396         1         1036   1036.0      0.2              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            3      3.0      0.0          self.sources_ = sources_
   400         1            1      1.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407                                                   return np.dot(X, self.components_.T)

Benchmark statement

obj.transform(X)

Execution time

_images/FastICA-parallel-arcene-step1-timing.png

Memory usage

_images/FastICA-parallel-arcene-step1-memory.png

Additional output

cProfile

         5 function calls in 0.016 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.016    0.016 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.016    0.016 <f>:1(<module>)
     1    0.000    0.000    0.016    0.016 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:402(transform)
     1    0.016    0.016    0.016    0.016 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 0.565591 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            4      4.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            2      2.0      0.0                          self.algorithm, self.whiten,
   392         1            2      2.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1       564536 564536.0     99.8                          random_state=self.random_state)
   395         1            5      5.0      0.0          if self.whiten == True:
   396         1         1036   1036.0      0.2              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            3      3.0      0.0          self.sources_ = sources_
   400         1            1      1.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0.009627 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407         1         9627   9627.0    100.0          return np.dot(X, self.components_.T)

FastICA-parallel-madelon

Benchmark setup

from sklearn.decomposition import FastICA
from deps import load_data

kwargs = {'n_components': 9, 'algorithm': 'parallel'}
X, y, X_t, y_t = load_data('madelon')
obj = FastICA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/FastICA-parallel-madelon-step0-timing.png

Memory usage

_images/FastICA-parallel-madelon-step0-memory.png

Additional output

cProfile

         12031 function calls in 5.004 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    5.004    5.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    5.004    5.004 <f>:1(<module>)
     1    0.000    0.000    5.004    5.004 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:389(fit)
     1    0.013    0.013    5.004    5.004 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:130(fastica)
     1    3.939    3.939    3.978    3.978 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
     1    0.030    0.030    0.889    0.889 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:94(_ica_par)
   199    0.512    0.003    0.512    0.003 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:229(g)
  1600    0.324    0.000    0.324    0.000 {numpy.core._dotblas.dot}
   200    0.008    0.000    0.095    0.000 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:40(_sym_decorrelation)
   200    0.051    0.000    0.072    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp.py:196(eigh)
   201    0.033    0.000    0.049    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   200    0.045    0.000    0.045    0.000 {method 'mean' of 'numpy.ndarray' objects}
   598    0.009    0.000    0.015    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
   402    0.015    0.000    0.015    0.000 {method 'any' of 'numpy.ndarray' objects}
   201    0.003    0.000    0.010    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
  1000    0.002    0.000    0.006    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
   201    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
  1001    0.003    0.000    0.003    0.000 {numpy.core.multiarray.array}
   797    0.003    0.000    0.003    0.000 {abs}
   200    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py:235(iscomplexobj)
   199    0.002    0.000    0.002    0.000 {max}
   399    0.001    0.000    0.001    0.000 {numpy.core.multiarray.zeros}
   401    0.001    0.000    0.001    0.000 {getattr}
   201    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
   602    0.001    0.000    0.001    0.000 {issubclass}
   404    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
  1202    0.000    0.000    0.000    0.000 {len}
   201    0.000    0.000    0.000    0.000 {range}
   201    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
   403    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
   201    0.000    0.000    0.000    0.000 {isinstance}
   201    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
   201    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
   200    0.000    0.000    0.000    0.000 {method 'get' of 'dict' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 {min}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 4.33803 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            4      4.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            3      3.0      0.0                          self.algorithm, self.whiten,
   392         1            3      3.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1      4337787 4337787.0    100.0                          random_state=self.random_state)
   395         1            6      6.0      0.0          if self.whiten == True:
   396         1          217    217.0      0.0              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            5      5.0      0.0          self.sources_ = sources_
   400         1            2      2.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407                                                   return np.dot(X, self.components_.T)

Benchmark statement

obj.transform(X)

Execution time

_images/FastICA-parallel-madelon-step1-timing.png

Memory usage

_images/FastICA-parallel-madelon-step1-memory.png

Additional output

cProfile

         5 function calls in 0.015 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.015    0.015 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.015    0.015 <f>:1(<module>)
     1    0.000    0.000    0.015    0.015 /tmp/vb_sklearn/sklearn/decomposition/fastica_.py:402(transform)
     1    0.015    0.015    0.015    0.015 {numpy.core._dotblas.dot}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: fit at line 389
Total time: 4.33803 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   389                                               def fit(self, X):
   390         1            4      4.0      0.0          whitening_, unmixing_, sources_ = fastica(X, self.n_components,
   391         1            3      3.0      0.0                          self.algorithm, self.whiten,
   392         1            3      3.0      0.0                          self.fun, self.fun_prime, self.fun_args, self.max_iter,
   393         1            2      2.0      0.0                          self.tol, self.w_init,
   394         1      4337787 4337787.0    100.0                          random_state=self.random_state)
   395         1            6      6.0      0.0          if self.whiten == True:
   396         1          217    217.0      0.0              self.components_ = np.dot(unmixing_, whitening_)
   397                                                   else:
   398                                                       self.components_ = unmixing_
   399         1            5      5.0      0.0          self.sources_ = sources_
   400         1            2      2.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/fastica_.py
Function: transform at line 402
Total time: 0.027392 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   402                                               def transform(self, X):
   403                                                   """Apply un-mixing matrix "W" to X to recover the sources
   404
   405                                                   S = X * W.T
   406                                                   """
   407         1        27392  27392.0    100.0          return np.dot(X, self.components_.T)

NMF-blobs

Benchmark setup

from sklearn.decomposition import NMF
from deps import load_data

kwargs = {'n_components': 2}
X, y, X_t, y_t = load_data('blobs')
obj = NMF(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/NMF-blobs-step0-timing.png

Memory usage

_images/NMF-blobs-step0-memory.png

Additional output

cProfile

         78864 function calls in 2.110 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    2.110    2.110 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    2.110    2.110 <f>:1(<module>)
     1    0.000    0.000    2.110    2.110 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:501(fit)
     1    0.080    0.080    2.110    2.110 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:432(fit_transform)
   400    0.806    0.002    1.881    0.005 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:160(_nls_subproblem)
   200    0.002    0.000    1.351    0.007 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:390(_update_W)
 12427    0.667    0.000    0.667    0.000 {numpy.core._dotblas.dot}
   200    0.001    0.000    0.534    0.003 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:411(_update_H)
 10710    0.032    0.000    0.212    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
  5357    0.172    0.000    0.172    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:23(_pos)
   804    0.025    0.000    0.152    0.000 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
 11111    0.132    0.000    0.132    0.000 {method 'sum' of 'numpy.ndarray' objects}
  3434    0.046    0.000    0.078    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:35(norm)
 13530    0.054    0.000    0.054    0.000 {isinstance}
   400    0.009    0.000    0.027    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:44(_sparseness)
  1812    0.004    0.000    0.026    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
  1812    0.015    0.000    0.023    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
   201    0.007    0.000    0.020    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
   400    0.003    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/linalg/linalg.py:1840(norm)
  3834    0.011    0.000    0.011    0.000 {method 'ravel' of 'numpy.ndarray' objects}
  1058    0.010    0.000    0.010    0.000 {method 'all' of 'numpy.ndarray' objects}
   201    0.001    0.000    0.009    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
   402    0.007    0.000    0.008    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
   406    0.005    0.000    0.005    0.000 {method 'any' of 'numpy.ndarray' objects}
  3630    0.005    0.000    0.005    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.005    0.005 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:363(_init)
     1    0.001    0.001    0.005    0.005 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:56(_initialize_nmf)
     1    0.000    0.000    0.004    0.004 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
   402    0.004    0.000    0.004    0.000 {abs}
   404    0.001    0.000    0.003    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
   201    0.002    0.000    0.002    0.000 {numpy.core.multiarray.concatenate}
   405    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
  3828    0.001    0.000    0.001    0.000 {len}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     1    0.001    0.001    0.001    0.001 {method 'normal' of 'mtrand.RandomState' objects}
   201    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
   205    0.000    0.000    0.000    0.000 {range}
   812    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:50(check_non_negative)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:28(_neg)
     2    0.000    0.000    0.000    0.000 {method 'randn' of 'mtrand.RandomState' objects}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 {_warnings.warn}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     5    0.000    0.000    0.000    0.000 {getattr}
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     8    0.000    0.000    0.000    0.000 {issubclass}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
     1    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {max}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit_transform at line 432
Total time: 2.47983 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   432                                               def fit_transform(self, X, y=None):
   433                                                   """Learn a NMF model for the data X and returns the transformed data.
   434
   435                                                   This is more efficient than calling fit followed by transform.
   436
   437                                                   Parameters
   438                                                   ----------
   439
   440                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   441                                                       Data matrix to be decomposed
   442
   443                                                   Returns
   444                                                   -------
   445                                                   data: array, [n_samples, n_components]
   446                                                       Transformed data
   447                                                   """
   448         1          168    168.0      0.0          X = atleast2d_or_csr(X)
   449         1          127    127.0      0.0          check_non_negative(X, "NMF.fit")
   450
   451         1            5      5.0      0.0          n_samples, n_features = X.shape
   452
   453         1            3      3.0      0.0          if not self.n_components:
   454                                                       self.n_components = n_features
   455
   456         1         4525   4525.0      0.2          W, H = self._init(X)
   457
   458         1          133    133.0      0.0          gradW = (np.dot(W, np.dot(H, H.T))
   459         1          265    265.0      0.0                   - safe_sparse_dot(X, H.T, dense_output=True))
   460         1          139    139.0      0.0          gradH = (np.dot(np.dot(W.T, W), H)
   461         1          240    240.0      0.0                   - safe_sparse_dot(W.T, X, dense_output=True))
   462         1          335    335.0      0.0          init_grad = norm(np.r_[gradW, gradH.T])
   463         1           14     14.0      0.0          tolW = max(0.001, self.tol) * init_grad  # why max?
   464         1            3      3.0      0.0          tolH = tolW
   465
   466       201          656      3.3      0.0          for n_iter in xrange(1, self.max_iter + 1):
   467                                                       # stopping condition
   468                                                       # as discussed in paper
   469       200        38175    190.9      1.5              proj_norm = norm(np.r_[gradW[np.logical_or(gradW < 0, W > 0)],
   470       200        62942    314.7      2.5                                     gradH[np.logical_or(gradH < 0, H > 0)]])
   471       200         2306     11.5      0.1              if proj_norm < self.tol * init_grad:
   472                                                           break
   473
   474                                                       # update W
   475       200      1569360   7846.8     63.3              W, gradW, iterW = self._update_W(X, H, W, tolW)
   476
   477       200         1260      6.3      0.1              W = W.T
   478       200          772      3.9      0.0              gradW = gradW.T
   479       200          623      3.1      0.0              if iterW == 1:
   480         1            9      9.0      0.0                  tolW = 0.1 * tolW
   481
   482                                                       # update H
   483       200       654588   3272.9     26.4              H, gradH, iterH = self._update_H(X, H, W, tolH)
   484
   485       200          948      4.7      0.0              if iterH == 1:
   486         1            9      9.0      0.0                  tolH = 0.1 * tolH
   487
   488       200        29030    145.2      1.2              self.comp_sparseness_ = _sparseness(H.ravel())
   489       200        22631    113.2      0.9              self.data_sparseness_ = _sparseness(W.ravel())
   490
   491       200         5458     27.3      0.2              if not sp.issparse(X):
   492       200        83993    420.0      3.4                  self.reconstruction_err_ = norm(X - np.dot(W, H))
   493
   494       200         1092      5.5      0.0              self.components_ = H
   495
   496         1            3      3.0      0.0          if n_iter == self.max_iter:
   497         1           16     16.0      0.0              warnings.warn("Iteration limit reached during fit")
   498
   499         1            3      3.0      0.0          return W

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit at line 501
Total time: 2.49312 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   501                                               def fit(self, X, y=None, **params):
   502                                                   """Learn a NMF model for the data X.
   503
   504                                                   Parameters
   505                                                   ----------
   506
   507                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   508                                                       Data matrix to be decomposed
   509
   510                                                   Returns
   511                                                   -------
   512                                                   self
   513                                                   """
   514         1      2493118 2493118.0    100.0          self.fit_transform(X, **params)
   515         1            1      1.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: transform at line 517
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   517                                               def transform(self, X):
   518                                                   """Transform the data X according to the fitted NMF model
   519
   520                                                   Parameters
   521                                                   ----------
   522
   523                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   524                                                       Data matrix to be transformed by the model
   525
   526                                                   Returns
   527                                                   -------
   528                                                   data: array, [n_samples, n_components]
   529                                                       Transformed data
   530                                                   """
   531                                                   X = atleast2d_or_csr(X)
   532                                                   H = np.zeros((X.shape[0], self.n_components))
   533                                                   for j in xrange(0, X.shape[0]):
   534                                                       H[j, :], _ = nnls(self.components_.T, X[j, :])
   535                                                   return H

Benchmark statement

obj.transform(X)

Execution time

_images/NMF-blobs-step1-timing.png

Memory usage

_images/NMF-blobs-step1-memory.png

Additional output

cProfile

         5128 function calls in 0.049 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.049    0.049 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.049    0.049 <f>:1(<module>)
     1    0.004    0.004    0.049    0.049 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:517(transform)
   300    0.006    0.000    0.045    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/optimize/nnls.py:7(nnls)
   300    0.001    0.000    0.037    0.000 {map}
   600    0.011    0.000    0.035    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
  1200    0.023    0.000    0.023    0.000 {method 'any' of 'numpy.ndarray' objects}
   601    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
   901    0.002    0.000    0.002    0.000 {numpy.core.multiarray.zeros}
   602    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}
   603    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     4    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.000    0.000 {isinstance}
     1    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit_transform at line 432
Total time: 2.47983 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   432                                               def fit_transform(self, X, y=None):
   433                                                   """Learn a NMF model for the data X and returns the transformed data.
   434
   435                                                   This is more efficient than calling fit followed by transform.
   436
   437                                                   Parameters
   438                                                   ----------
   439
   440                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   441                                                       Data matrix to be decomposed
   442
   443                                                   Returns
   444                                                   -------
   445                                                   data: array, [n_samples, n_components]
   446                                                       Transformed data
   447                                                   """
   448         1          168    168.0      0.0          X = atleast2d_or_csr(X)
   449         1          127    127.0      0.0          check_non_negative(X, "NMF.fit")
   450
   451         1            5      5.0      0.0          n_samples, n_features = X.shape
   452
   453         1            3      3.0      0.0          if not self.n_components:
   454                                                       self.n_components = n_features
   455
   456         1         4525   4525.0      0.2          W, H = self._init(X)
   457
   458         1          133    133.0      0.0          gradW = (np.dot(W, np.dot(H, H.T))
   459         1          265    265.0      0.0                   - safe_sparse_dot(X, H.T, dense_output=True))
   460         1          139    139.0      0.0          gradH = (np.dot(np.dot(W.T, W), H)
   461         1          240    240.0      0.0                   - safe_sparse_dot(W.T, X, dense_output=True))
   462         1          335    335.0      0.0          init_grad = norm(np.r_[gradW, gradH.T])
   463         1           14     14.0      0.0          tolW = max(0.001, self.tol) * init_grad  # why max?
   464         1            3      3.0      0.0          tolH = tolW
   465
   466       201          656      3.3      0.0          for n_iter in xrange(1, self.max_iter + 1):
   467                                                       # stopping condition
   468                                                       # as discussed in paper
   469       200        38175    190.9      1.5              proj_norm = norm(np.r_[gradW[np.logical_or(gradW < 0, W > 0)],
   470       200        62942    314.7      2.5                                     gradH[np.logical_or(gradH < 0, H > 0)]])
   471       200         2306     11.5      0.1              if proj_norm < self.tol * init_grad:
   472                                                           break
   473
   474                                                       # update W
   475       200      1569360   7846.8     63.3              W, gradW, iterW = self._update_W(X, H, W, tolW)
   476
   477       200         1260      6.3      0.1              W = W.T
   478       200          772      3.9      0.0              gradW = gradW.T
   479       200          623      3.1      0.0              if iterW == 1:
   480         1            9      9.0      0.0                  tolW = 0.1 * tolW
   481
   482                                                       # update H
   483       200       654588   3272.9     26.4              H, gradH, iterH = self._update_H(X, H, W, tolH)
   484
   485       200          948      4.7      0.0              if iterH == 1:
   486         1            9      9.0      0.0                  tolH = 0.1 * tolH
   487
   488       200        29030    145.2      1.2              self.comp_sparseness_ = _sparseness(H.ravel())
   489       200        22631    113.2      0.9              self.data_sparseness_ = _sparseness(W.ravel())
   490
   491       200         5458     27.3      0.2              if not sp.issparse(X):
   492       200        83993    420.0      3.4                  self.reconstruction_err_ = norm(X - np.dot(W, H))
   493
   494       200         1092      5.5      0.0              self.components_ = H
   495
   496         1            3      3.0      0.0          if n_iter == self.max_iter:
   497         1           16     16.0      0.0              warnings.warn("Iteration limit reached during fit")
   498
   499         1            3      3.0      0.0          return W

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit at line 501
Total time: 2.49312 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   501                                               def fit(self, X, y=None, **params):
   502                                                   """Learn a NMF model for the data X.
   503
   504                                                   Parameters
   505                                                   ----------
   506
   507                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   508                                                       Data matrix to be decomposed
   509
   510                                                   Returns
   511                                                   -------
   512                                                   self
   513                                                   """
   514         1      2493118 2493118.0    100.0          self.fit_transform(X, **params)
   515         1            1      1.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: transform at line 517
Total time: 0.043517 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   517                                               def transform(self, X):
   518                                                   """Transform the data X according to the fitted NMF model
   519
   520                                                   Parameters
   521                                                   ----------
   522
   523                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   524                                                       Data matrix to be transformed by the model
   525
   526                                                   Returns
   527                                                   -------
   528                                                   data: array, [n_samples, n_components]
   529                                                       Transformed data
   530                                                   """
   531         1          157    157.0      0.4          X = atleast2d_or_csr(X)
   532         1           10     10.0      0.0          H = np.zeros((X.shape[0], self.n_components))
   533       301          784      2.6      1.8          for j in xrange(0, X.shape[0]):
   534       300        42565    141.9     97.8              H[j, :], _ = nnls(self.components_.T, X[j, :])
   535         1            1      1.0      0.0          return H

Benchmark statement

obj.fit_transform(X)

Execution time

_images/NMF-blobs-step2-timing.png

Memory usage

_images/NMF-blobs-step2-memory.png

Additional output

cProfile

         78280 function calls in 2.177 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    2.177    2.177 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    2.177    2.177 <f>:1(<module>)
     1    0.057    0.057    2.177    2.177 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:432(fit_transform)
   400    0.833    0.002    1.947    0.005 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:160(_nls_subproblem)
   200    0.002    0.000    1.405    0.007 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:390(_update_W)
 12320    0.686    0.000    0.686    0.000 {numpy.core._dotblas.dot}
   200    0.001    0.000    0.545    0.003 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:411(_update_H)
 10592    0.031    0.000    0.209    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
  5298    0.170    0.000    0.170    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:23(_pos)
 10993    0.153    0.000    0.153    0.000 {method 'sum' of 'numpy.ndarray' objects}
   804    0.014    0.000    0.153    0.000 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
  3410    0.046    0.000    0.104    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:35(norm)
  1812    0.004    0.000    0.051    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
  1812    0.028    0.000    0.047    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
   201    0.019    0.000    0.032    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
 13412    0.031    0.000    0.031    0.000 {isinstance}
   400    0.009    0.000    0.027    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:44(_sparseness)
  3810    0.023    0.000    0.023    0.000 {method 'ravel' of 'numpy.ndarray' objects}
  1043    0.022    0.000    0.022    0.000 {method 'all' of 'numpy.ndarray' objects}
  3630    0.016    0.000    0.016    0.000 {method 'split' of 'str' objects}
   400    0.003    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/linalg/linalg.py:1840(norm)
   201    0.001    0.000    0.009    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
   402    0.007    0.000    0.008    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
   406    0.005    0.000    0.005    0.000 {method 'any' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.004    0.004 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:363(_init)
     1    0.001    0.001    0.004    0.004 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:56(_initialize_nmf)
   402    0.004    0.000    0.004    0.000 {abs}
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
   404    0.001    0.000    0.003    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
   201    0.002    0.000    0.002    0.000 {numpy.core.multiarray.concatenate}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
   405    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
  3828    0.001    0.000    0.001    0.000 {len}
     1    0.001    0.001    0.001    0.001 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
   201    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
   812    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
   205    0.000    0.000    0.000    0.000 {range}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:50(check_non_negative)
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
     1    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {method 'randn' of 'mtrand.RandomState' objects}
     2    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/decomposition/nmf.py:28(_neg)
     4    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     3    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     5    0.000    0.000    0.000    0.000 {getattr}
     1    0.000    0.000    0.000    0.000 {_warnings.warn}
     8    0.000    0.000    0.000    0.000 {issubclass}
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.arange}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     2    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {max}
     1    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit_transform at line 432
Total time: 4.96668 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   432                                               def fit_transform(self, X, y=None):
   433                                                   """Learn a NMF model for the data X and returns the transformed data.
   434
   435                                                   This is more efficient than calling fit followed by transform.
   436
   437                                                   Parameters
   438                                                   ----------
   439
   440                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   441                                                       Data matrix to be decomposed
   442
   443                                                   Returns
   444                                                   -------
   445                                                   data: array, [n_samples, n_components]
   446                                                       Transformed data
   447                                                   """
   448         2          323    161.5      0.0          X = atleast2d_or_csr(X)
   449         2          255    127.5      0.0          check_non_negative(X, "NMF.fit")
   450
   451         2           10      5.0      0.0          n_samples, n_features = X.shape
   452
   453         2            7      3.5      0.0          if not self.n_components:
   454                                                       self.n_components = n_features
   455
   456         2         9029   4514.5      0.2          W, H = self._init(X)
   457
   458         2          267    133.5      0.0          gradW = (np.dot(W, np.dot(H, H.T))
   459         2          522    261.0      0.0                   - safe_sparse_dot(X, H.T, dense_output=True))
   460         2          278    139.0      0.0          gradH = (np.dot(np.dot(W.T, W), H)
   461         2          480    240.0      0.0                   - safe_sparse_dot(W.T, X, dense_output=True))
   462         2          609    304.5      0.0          init_grad = norm(np.r_[gradW, gradH.T])
   463         2           28     14.0      0.0          tolW = max(0.001, self.tol) * init_grad  # why max?
   464         2            6      3.0      0.0          tolH = tolW
   465
   466       402         1326      3.3      0.0          for n_iter in xrange(1, self.max_iter + 1):
   467                                                       # stopping condition
   468                                                       # as discussed in paper
   469       400        65964    164.9      1.3              proj_norm = norm(np.r_[gradW[np.logical_or(gradW < 0, W > 0)],
   470       400       128388    321.0      2.6                                     gradH[np.logical_or(gradH < 0, H > 0)]])
   471       400         4823     12.1      0.1              if proj_norm < self.tol * init_grad:
   472                                                           break
   473
   474                                                       # update W
   475       400      3113841   7784.6     62.7              W, gradW, iterW = self._update_W(X, H, W, tolW)
   476
   477       400         2567      6.4      0.1              W = W.T
   478       400         1568      3.9      0.0              gradW = gradW.T
   479       400         1288      3.2      0.0              if iterW == 1:
   480         2           20     10.0      0.0                  tolW = 0.1 * tolW
   481
   482                                                       # update H
   483       400      1317520   3293.8     26.5              H, gradH, iterH = self._update_H(X, H, W, tolH)
   484
   485       400         1927      4.8      0.0              if iterH == 1:
   486         2           19      9.5      0.0                  tolH = 0.1 * tolH
   487
   488       400        61358    153.4      1.2              self.comp_sparseness_ = _sparseness(H.ravel())
   489       400        46159    115.4      0.9              self.data_sparseness_ = _sparseness(W.ravel())
   490
   491       400        11222     28.1      0.2              if not sp.issparse(X):
   492       400       194511    486.3      3.9                  self.reconstruction_err_ = norm(X - np.dot(W, H))
   493
   494       400         2316      5.8      0.0              self.components_ = H
   495
   496         2            6      3.0      0.0          if n_iter == self.max_iter:
   497         2           33     16.5      0.0              warnings.warn("Iteration limit reached during fit")
   498
   499         2            6      3.0      0.0          return W

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: fit at line 501
Total time: 2.49312 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   501                                               def fit(self, X, y=None, **params):
   502                                                   """Learn a NMF model for the data X.
   503
   504                                                   Parameters
   505                                                   ----------
   506
   507                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   508                                                       Data matrix to be decomposed
   509
   510                                                   Returns
   511                                                   -------
   512                                                   self
   513                                                   """
   514         1      2493118 2493118.0    100.0          self.fit_transform(X, **params)
   515         1            1      1.0      0.0          return self

File: /tmp/vb_sklearn/sklearn/decomposition/nmf.py
Function: transform at line 517
Total time: 0.043517 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   517                                               def transform(self, X):
   518                                                   """Transform the data X according to the fitted NMF model
   519
   520                                                   Parameters
   521                                                   ----------
   522
   523                                                   X: {array-like, sparse matrix}, shape = [n_samples, n_features]
   524                                                       Data matrix to be transformed by the model
   525
   526                                                   Returns
   527                                                   -------
   528                                                   data: array, [n_samples, n_components]
   529                                                       Transformed data
   530                                                   """
   531         1          157    157.0      0.4          X = atleast2d_or_csr(X)
   532         1           10     10.0      0.0          H = np.zeros((X.shape[0], self.n_components))
   533       301          784      2.6      1.8          for j in xrange(0, X.shape[0]):
   534       300        42565    141.9     97.8              H[j, :], _ = nnls(self.components_.T, X[j, :])
   535         1            1      1.0      0.0          return H

MiniBatchDictionaryLearning-blobs

Benchmark setup

from sklearn.decomposition import MiniBatchDictionaryLearning
from deps import load_data

kwargs = {'n_iter': 300, 'n_atoms': 50}
X, y, X_t, y_t = load_data('blobs')
obj = MiniBatchDictionaryLearning(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/MiniBatchDictionaryLearning-blobs-step0-timing.png

Memory usage

_images/MiniBatchDictionaryLearning-blobs-step0-memory.png

Additional output

cProfile

         422257 function calls in 11.861 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000   11.861   11.861 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000   11.861   11.861 <f>:1(<module>)
     1    0.000    0.000   11.861   11.861 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:1107(fit)
     1    0.035    0.035   11.861   11.861 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:524(dict_learning_online)
   300    0.008    0.000    9.893    0.033 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:178(sparse_encode)
   300    0.031    0.000    9.778    0.033 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:24(_sparse_encode)
   900    7.541    0.008    9.732    0.011 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
   300    1.443    0.005    1.815    0.006 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:298(_update_dict)
 62706    0.869    0.000    0.869    0.000 {numpy.core._dotblas.dot}
  2175    0.067    0.000    0.740    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3267(delete)
  2175    0.112    0.000    0.625    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:376(setdiff1d)
  4350    0.152    0.000    0.325    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
 14404    0.078    0.000    0.292    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
 13050    0.236    0.000    0.236    0.000 {numpy.core.multiarray.concatenate}
  2175    0.077    0.000    0.190    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
  2175    0.072    0.000    0.176    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:281(in1d)
 14404    0.159    0.000    0.159    0.000 {method 'sum' of 'numpy.ndarray' objects}
 15304    0.035    0.000    0.120    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
 43212    0.119    0.000    0.119    0.000 {sklearn.utils.arrayfuncs.min_pos}
 15304    0.084    0.000    0.084    0.000 {method 'argmax' of 'numpy.ndarray' objects}
 29263    0.079    0.000    0.079    0.000 {isinstance}
  2175    0.024    0.000    0.077    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3525(append)
 15304    0.072    0.000    0.072    0.000 {min}
 14556    0.066    0.000    0.066    0.000 {numpy.core.multiarray.array}
  1200    0.044    0.000    0.059    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
 12449    0.051    0.000    0.051    0.000 {sklearn.utils.arrayfuncs.solve_triangular}
   903    0.024    0.000    0.046    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
  2175    0.031    0.000    0.043    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
  4350    0.043    0.000    0.043    0.000 {method 'argsort' of 'numpy.ndarray' objects}
  7729    0.016    0.000    0.038    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
  3077    0.030    0.000    0.030    0.000 {numpy.core.multiarray.arange}
 13649    0.024    0.000    0.024    0.000 {max}
  2175    0.006    0.000    0.020    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
   904    0.010    0.000    0.018    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
  4350    0.017    0.000    0.017    0.000 {method 'flatten' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.017    0.017 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
 27331    0.014    0.000    0.014    0.000 {method 'append' of 'list' objects}
  1800    0.006    0.000    0.013    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
  4350    0.013    0.000    0.013    0.000 {method 'sort' of 'numpy.ndarray' objects}
  1801    0.012    0.000    0.012    0.000 {method 'copy' of 'numpy.ndarray' objects}
  2175    0.012    0.000    0.012    0.000 {sklearn.utils.arrayfuncs.cholesky_delete}
 15000    0.012    0.000    0.012    0.000 {math.sqrt}
  2175    0.005    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
   600    0.004    0.000    0.010    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2036(seterr)
     1    0.009    0.009    0.010    0.010 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
  1802    0.010    0.000    0.010    0.000 {numpy.core.multiarray.zeros}
  5105    0.009    0.000    0.009    0.000 {getattr}
  5100    0.008    0.000    0.008    0.000 {method 'get' of 'dict' objects}
  5556    0.008    0.000    0.008    0.000 {range}
  2175    0.008    0.000    0.008    0.000 {numpy.core.multiarray.where}
  4350    0.007    0.000    0.008    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
  2100    0.008    0.000    0.008    0.000 {numpy.core.multiarray.empty}
   300    0.001    0.000    0.007    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
  2176    0.006    0.000    0.006    0.000 {method 'astype' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.006    0.006 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
  2175    0.005    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
  2175    0.005    0.000    0.005    0.000 {method 'pop' of 'list' objects}
     1    0.000    0.000    0.005    0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:356(array_split)
     1    0.003    0.003    0.004    0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:348(_replace_zero_by_x_arrays)
  4350    0.004    0.000    0.004    0.000 {method 'index' of 'list' objects}
   904    0.003    0.000    0.004    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
 10010    0.004    0.000    0.004    0.000 {len}
   600    0.003    0.000    0.004    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2132(geterr)
  2175    0.004    0.000    0.004    0.000 {method 'ravel' of 'numpy.ndarray' objects}
   304    0.002    0.000    0.003    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.003    0.003    0.003    0.003 {method 'normal' of 'mtrand.RandomState' objects}
  1814    0.003    0.000    0.003    0.000 {method 'split' of 'str' objects}
     2    0.000    0.000    0.002    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.002    0.002    0.002    0.002 {method 'shuffle' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.001    0.001    0.002    0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
  1808    0.001    0.000    0.001    0.000 {issubclass}
   600    0.001    0.000    0.001    0.000 {numpy.core.umath.seterrobj}
   904    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
  1200    0.001    0.000    0.001    0.000 {numpy.core.umath.geterrobj}
   904    0.001    0.000    0.001    0.000 {method 'sort' of 'list' objects}
   100    0.000    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1474(sometrue)
   104    0.001    0.000    0.001    0.000 {method 'any' of 'numpy.ndarray' objects}
     2    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   301    0.000    0.000    0.000    0.000 {time.time}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
   101    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:397(swapaxes)
   200    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1211(shape)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
   101    0.000    0.000    0.000    0.000 {method 'swapaxes' of 'numpy.ndarray' objects}
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     1    0.000    0.000    0.000    0.000 {method 'cumsum' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:289(ascontiguousarray)
     1    0.000    0.000    0.000    0.000 {hasattr}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {divmod}
     1    0.000    0.000    0.000    0.000 {math.floor}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358                                                   if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360                                                       return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: transform at line 716
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   716                                               def transform(self, X, y=None):
   717                                                   """Encode the data as a sparse combination of the dictionary atoms.
   718
   719                                                   Coding method is determined by the object parameter
   720                                                   `transform_algorithm`.
   721
   722                                                   Parameters
   723                                                   ----------
   724                                                   X : array of shape (n_samples, n_features)
   725                                                       Test data to be transformed, must have the same number of
   726                                                       features as the data used to train the model.
   727
   728                                                   Returns
   729                                                   -------
   730                                                   X_new : array, shape (n_samples, n_components)
   731                                                       Transformed data
   732
   733                                                   """
   734                                                   # XXX : kwargs is not documented
   735                                                   X = array2d(X)
   736                                                   n_samples, n_features = X.shape
   737
   738                                                   code = sparse_encode(
   739                                                       X, self.components_, algorithm=self.transform_algorithm,
   740                                                       n_nonzero_coefs=self.transform_n_nonzero_coefs,
   741                                                       alpha=self.transform_alpha, n_jobs=self.n_jobs)
   742
   743                                                   if self.split_sign:
   744                                                       # feature vector is split into a positive and negative side
   745                                                       n_samples, n_features = code.shape
   746                                                       split_code = np.empty((n_samples, 2 * n_features))
   747                                                       split_code[:, :n_features] = np.maximum(code, 0)
   748                                                       split_code[:, n_features:] = -np.minimum(code, 0)
   749                                                       code = split_code
   750
   751                                                   return code

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: fit at line 1107
Total time: 15.646 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
  1107                                               def fit(self, X, y=None):
  1108                                                   """Fit the model from data in X.
  1109
  1110                                                   Parameters
  1111                                                   ----------
  1112                                                   X: array-like, shape (n_samples, n_features)
  1113                                                       Training vector, where n_samples in the number of samples
  1114                                                       and n_features is the number of features.
  1115
  1116                                                   Returns
  1117                                                   -------
  1118                                                   self : object
  1119                                                       Returns the instance itself.
  1120                                                   """
  1121         1           11     11.0      0.0          self.random_state = check_random_state(self.random_state)
  1122         1           13     13.0      0.0          X = np.asarray(X)
  1123         1            3      3.0      0.0          if self.n_atoms is None:
  1124                                                       n_atoms = X.shape[1]
  1125                                                   else:
  1126         1            3      3.0      0.0              n_atoms = self.n_atoms
  1127
  1128         1            2      2.0      0.0          U = dict_learning_online(X, n_atoms, self.alpha,
  1129         1            3      3.0      0.0                                   n_iter=self.n_iter, return_code=False,
  1130         1            3      3.0      0.0                                   method=self.fit_algorithm,
  1131         1            2      2.0      0.0                                   n_jobs=self.n_jobs,
  1132         1            2      2.0      0.0                                   dict_init=self.dict_init,
  1133         1            2      2.0      0.0                                   chunk_size=self.chunk_size,
  1134         1            3      3.0      0.0                                   shuffle=self.shuffle, verbose=self.verbose,
  1135         1     15645923 15645923.0    100.0                                   random_state=self.random_state)
  1136         1            5      5.0      0.0          self.components_ = U
  1137         1            2      2.0      0.0          return self

Benchmark statement

obj.transform(X)

Execution time

_images/MiniBatchDictionaryLearning-blobs-step1-timing.png

Memory usage

_images/MiniBatchDictionaryLearning-blobs-step1-memory.png

Additional output

cProfile

         15346 function calls in 0.343 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.343    0.343 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.343    0.343 <f>:1(<module>)
     1    0.000    0.000    0.343    0.343 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:716(transform)
     1    0.000    0.000    0.343    0.343 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:178(sparse_encode)
     1    0.000    0.000    0.342    0.342 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:24(_sparse_encode)
     1    0.015    0.015    0.342    0.342 /tmp/vb_sklearn/sklearn/linear_model/omp.py:311(orthogonal_mp_gram)
   300    0.270    0.001    0.327    0.001 /tmp/vb_sklearn/sklearn/linear_model/omp.py:107(_gram_omp)
   300    0.004    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
  1502    0.010    0.000    0.010    0.000 {numpy.core._dotblas.dot}
   300    0.008    0.000    0.010    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
  1500    0.003    0.000    0.010    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
  1500    0.007    0.000    0.007    0.000 {method 'argmax' of 'numpy.ndarray' objects}
   300    0.003    0.000    0.006    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
   300    0.005    0.000    0.005    0.000 {method 'copy' of 'numpy.ndarray' objects}
  1200    0.004    0.000    0.004    0.000 {sklearn.utils.arrayfuncs.solve_triangular}
   300    0.001    0.000    0.003    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
   600    0.003    0.000    0.003    0.000 {numpy.core.multiarray.empty}
  1200    0.002    0.000    0.002    0.000 {method 'get' of 'dict' objects}
   300    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
   601    0.001    0.000    0.001    0.000 {range}
   900    0.001    0.000    0.001    0.000 {getattr}
   602    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
   302    0.001    0.000    0.001    0.000 {isinstance}
   600    0.001    0.000    0.001    0.000 {issubclass}
  1201    0.001    0.000    0.001    0.000 {method 'append' of 'list' objects}
   300    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
   301    0.000    0.000    0.000    0.000 {max}
   300    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
   605    0.000    0.000    0.000    0.000 {len}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 {method 'sum' of 'numpy.ndarray' objects}
     7    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     8    0.000    0.000    0.000    0.000 {numpy.core.multiarray.array}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:871(squeeze)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
     1    0.000    0.000    0.000    0.000 {method 'squeeze' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358                                                   if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360                                                       return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: transform at line 716
Total time: 0.44922 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   716                                               def transform(self, X, y=None):
   717                                                   """Encode the data as a sparse combination of the dictionary atoms.
   718
   719                                                   Coding method is determined by the object parameter
   720                                                   `transform_algorithm`.
   721
   722                                                   Parameters
   723                                                   ----------
   724                                                   X : array of shape (n_samples, n_features)
   725                                                       Test data to be transformed, must have the same number of
   726                                                       features as the data used to train the model.
   727
   728                                                   Returns
   729                                                   -------
   730                                                   X_new : array, shape (n_samples, n_components)
   731                                                       Transformed data
   732
   733                                                   """
   734                                                   # XXX : kwargs is not documented
   735         1           64     64.0      0.0          X = array2d(X)
   736         1            3      3.0      0.0          n_samples, n_features = X.shape
   737
   738         1            2      2.0      0.0          code = sparse_encode(
   739         1            3      3.0      0.0              X, self.components_, algorithm=self.transform_algorithm,
   740         1            2      2.0      0.0              n_nonzero_coefs=self.transform_n_nonzero_coefs,
   741         1       449139 449139.0    100.0              alpha=self.transform_alpha, n_jobs=self.n_jobs)
   742
   743         1            4      4.0      0.0          if self.split_sign:
   744                                                       # feature vector is split into a positive and negative side
   745                                                       n_samples, n_features = code.shape
   746                                                       split_code = np.empty((n_samples, 2 * n_features))
   747                                                       split_code[:, :n_features] = np.maximum(code, 0)
   748                                                       split_code[:, n_features:] = -np.minimum(code, 0)
   749                                                       code = split_code
   750
   751         1            3      3.0      0.0          return code

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: fit at line 1107
Total time: 15.646 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
  1107                                               def fit(self, X, y=None):
  1108                                                   """Fit the model from data in X.
  1109
  1110                                                   Parameters
  1111                                                   ----------
  1112                                                   X: array-like, shape (n_samples, n_features)
  1113                                                       Training vector, where n_samples in the number of samples
  1114                                                       and n_features is the number of features.
  1115
  1116                                                   Returns
  1117                                                   -------
  1118                                                   self : object
  1119                                                       Returns the instance itself.
  1120                                                   """
  1121         1           11     11.0      0.0          self.random_state = check_random_state(self.random_state)
  1122         1           13     13.0      0.0          X = np.asarray(X)
  1123         1            3      3.0      0.0          if self.n_atoms is None:
  1124                                                       n_atoms = X.shape[1]
  1125                                                   else:
  1126         1            3      3.0      0.0              n_atoms = self.n_atoms
  1127
  1128         1            2      2.0      0.0          U = dict_learning_online(X, n_atoms, self.alpha,
  1129         1            3      3.0      0.0                                   n_iter=self.n_iter, return_code=False,
  1130         1            3      3.0      0.0                                   method=self.fit_algorithm,
  1131         1            2      2.0      0.0                                   n_jobs=self.n_jobs,
  1132         1            2      2.0      0.0                                   dict_init=self.dict_init,
  1133         1            2      2.0      0.0                                   chunk_size=self.chunk_size,
  1134         1            3      3.0      0.0                                   shuffle=self.shuffle, verbose=self.verbose,
  1135         1     15645923 15645923.0    100.0                                   random_state=self.random_state)
  1136         1            5      5.0      0.0          self.components_ = U
  1137         1            2      2.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/MiniBatchDictionaryLearning-blobs-step2-timing.png

Memory usage

_images/MiniBatchDictionaryLearning-blobs-step2-memory.png

Additional output

cProfile

         398764 function calls in 11.729 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000   11.729   11.729 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000   11.729   11.729 <f>:1(<module>)
     1    0.000    0.000   11.729   11.729 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     1    0.000    0.000   11.387   11.387 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:1107(fit)
     1    0.036    0.036   11.387   11.387 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:524(dict_learning_online)
   301    0.008    0.000    9.770    0.032 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:178(sparse_encode)
   301    0.032    0.000    9.638    0.032 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:24(_sparse_encode)
   900    7.261    0.008    9.250    0.010 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
   300    1.405    0.005    1.802    0.006 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:298(_update_dict)
 62908    0.937    0.000    0.937    0.000 {numpy.core._dotblas.dot}
  1576    0.052    0.000    0.542    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3267(delete)
  1576    0.050    0.000    0.452    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:376(setdiff1d)
     1    0.000    0.000    0.342    0.342 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:716(transform)
     1    0.027    0.027    0.341    0.341 /tmp/vb_sklearn/sklearn/linear_model/omp.py:311(orthogonal_mp_gram)
   300    0.243    0.001    0.314    0.001 /tmp/vb_sklearn/sklearn/linear_model/omp.py:107(_gram_omp)
 14090    0.057    0.000    0.263    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
  3152    0.121    0.000    0.245    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
  9456    0.162    0.000    0.162    0.000 {numpy.core.multiarray.concatenate}
 16488    0.053    0.000    0.157    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
 42267    0.154    0.000    0.154    0.000 {sklearn.utils.arrayfuncs.min_pos}
 14090    0.150    0.000    0.150    0.000 {method 'sum' of 'numpy.ndarray' objects}
  1576    0.057    0.000    0.149    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:281(in1d)
  1576    0.058    0.000    0.148    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
 16488    0.104    0.000    0.104    0.000 {method 'argmax' of 'numpy.ndarray' objects}
 25658    0.088    0.000    0.088    0.000 {isinstance}
 14989    0.085    0.000    0.085    0.000 {min}
 13862    0.070    0.000    0.070    0.000 {sklearn.utils.arrayfuncs.solve_triangular}
  1500    0.044    0.000    0.062    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
  1203    0.017    0.000    0.060    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
  1576    0.037    0.000    0.046    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
 10970    0.044    0.000    0.044    0.000 {numpy.core.multiarray.array}
  1576    0.010    0.000    0.041    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3525(append)
  1204    0.013    0.000    0.037    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
  3152    0.034    0.000    0.034    0.000 {method 'argsort' of 'numpy.ndarray' objects}
  1803    0.032    0.000    0.032    0.000 {numpy.core.multiarray.zeros}
  5939    0.012    0.000    0.030    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
 14163    0.025    0.000    0.025    0.000 {max}
  1204    0.016    0.000    0.018    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
  2101    0.017    0.000    0.017    0.000 {method 'copy' of 'numpy.ndarray' objects}
  2100    0.007    0.000    0.016    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
     1    0.000    0.000    0.016    0.016 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
  8219    0.015    0.000    0.015    0.000 {len}
  1576    0.004    0.000    0.015    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
  2478    0.015    0.000    0.015    0.000 {numpy.core.multiarray.arange}
 15000    0.013    0.000    0.013    0.000 {math.sqrt}
 25750    0.013    0.000    0.013    0.000 {method 'append' of 'list' objects}
  3152    0.013    0.000    0.013    0.000 {method 'flatten' of 'numpy.ndarray' objects}
  6300    0.011    0.000    0.011    0.000 {method 'get' of 'dict' objects}
  2700    0.011    0.000    0.011    0.000 {numpy.core.multiarray.empty}
  6005    0.010    0.000    0.010    0.000 {getattr}
   600    0.005    0.000    0.010    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2036(seterr)
  3152    0.010    0.000    0.010    0.000 {method 'sort' of 'numpy.ndarray' objects}
     1    0.009    0.009    0.009    0.009 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
  1576    0.009    0.000    0.009    0.000 {sklearn.utils.arrayfuncs.cholesky_delete}
  1577    0.004    0.000    0.009    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
  4959    0.008    0.000    0.008    0.000 {range}
   300    0.001    0.000    0.008    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
  1576    0.006    0.000    0.006    0.000 {numpy.core.multiarray.where}
  3152    0.005    0.000    0.006    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
     1    0.000    0.000    0.005    0.005 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
     1    0.000    0.000    0.005    0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:356(array_split)
  1577    0.005    0.000    0.005    0.000 {method 'astype' of 'numpy.ndarray' objects}
     1    0.003    0.003    0.004    0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:348(_replace_zero_by_x_arrays)
  1576    0.004    0.000    0.004    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
  1576    0.004    0.000    0.004    0.000 {method 'pop' of 'list' objects}
  2416    0.004    0.000    0.004    0.000 {method 'split' of 'str' objects}
   600    0.003    0.000    0.004    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2132(geterr)
   304    0.002    0.000    0.003    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
  3152    0.003    0.000    0.003    0.000 {method 'index' of 'list' objects}
     1    0.003    0.003    0.003    0.003 {method 'normal' of 'mtrand.RandomState' objects}
  1576    0.003    0.000    0.003    0.000 {method 'ravel' of 'numpy.ndarray' objects}
  2408    0.002    0.000    0.002    0.000 {issubclass}
     2    0.000    0.000    0.002    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.002    0.002    0.002    0.002 {method 'shuffle' of 'mtrand.RandomState' objects}
  1204    0.002    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
   600    0.001    0.000    0.001    0.000 {numpy.core.umath.seterrobj}
  1204    0.001    0.000    0.001    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
  1200    0.001    0.000    0.001    0.000 {numpy.core.umath.geterrobj}
   100    0.000    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1474(sometrue)
   104    0.001    0.000    0.001    0.000 {method 'any' of 'numpy.ndarray' objects}
     2    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   301    0.000    0.000    0.000    0.000 {time.time}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
   200    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1211(shape)
   101    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:397(swapaxes)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
     5    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     5    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
   101    0.000    0.000    0.000    0.000 {method 'swapaxes' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     1    0.000    0.000    0.000    0.000 {method 'cumsum' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:289(ascontiguousarray)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:871(squeeze)
     1    0.000    0.000    0.000    0.000 {divmod}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {math.floor}
     1    0.000    0.000    0.000    0.000 {method 'squeeze' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 16.2049 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358         1            3      3.0      0.0          if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360         1     16204912 16204912.0    100.0              return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: transform at line 716
Total time: 0.909819 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   716                                               def transform(self, X, y=None):
   717                                                   """Encode the data as a sparse combination of the dictionary atoms.
   718
   719                                                   Coding method is determined by the object parameter
   720                                                   `transform_algorithm`.
   721
   722                                                   Parameters
   723                                                   ----------
   724                                                   X : array of shape (n_samples, n_features)
   725                                                       Test data to be transformed, must have the same number of
   726                                                       features as the data used to train the model.
   727
   728                                                   Returns
   729                                                   -------
   730                                                   X_new : array, shape (n_samples, n_components)
   731                                                       Transformed data
   732
   733                                                   """
   734                                                   # XXX : kwargs is not documented
   735         2          174     87.0      0.0          X = array2d(X)
   736         2            7      3.5      0.0          n_samples, n_features = X.shape
   737
   738         2            5      2.5      0.0          code = sparse_encode(
   739         2            6      3.0      0.0              X, self.components_, algorithm=self.transform_algorithm,
   740         2            5      2.5      0.0              n_nonzero_coefs=self.transform_n_nonzero_coefs,
   741         2       909609 454804.5    100.0              alpha=self.transform_alpha, n_jobs=self.n_jobs)
   742
   743         2            8      4.0      0.0          if self.split_sign:
   744                                                       # feature vector is split into a positive and negative side
   745                                                       n_samples, n_features = code.shape
   746                                                       split_code = np.empty((n_samples, 2 * n_features))
   747                                                       split_code[:, :n_features] = np.maximum(code, 0)
   748                                                       split_code[:, n_features:] = -np.minimum(code, 0)
   749                                                       code = split_code
   750
   751         2            5      2.5      0.0          return code

File: /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py
Function: fit at line 1107
Total time: 31.3902 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
  1107                                               def fit(self, X, y=None):
  1108                                                   """Fit the model from data in X.
  1109
  1110                                                   Parameters
  1111                                                   ----------
  1112                                                   X: array-like, shape (n_samples, n_features)
  1113                                                       Training vector, where n_samples in the number of samples
  1114                                                       and n_features is the number of features.
  1115
  1116                                                   Returns
  1117                                                   -------
  1118                                                   self : object
  1119                                                       Returns the instance itself.
  1120                                                   """
  1121         2           26     13.0      0.0          self.random_state = check_random_state(self.random_state)
  1122         2           24     12.0      0.0          X = np.asarray(X)
  1123         2            6      3.0      0.0          if self.n_atoms is None:
  1124                                                       n_atoms = X.shape[1]
  1125                                                   else:
  1126         2            5      2.5      0.0              n_atoms = self.n_atoms
  1127
  1128         2            5      2.5      0.0          U = dict_learning_online(X, n_atoms, self.alpha,
  1129         2            6      3.0      0.0                                   n_iter=self.n_iter, return_code=False,
  1130         2            5      2.5      0.0                                   method=self.fit_algorithm,
  1131         2            4      2.0      0.0                                   n_jobs=self.n_jobs,
  1132         2            4      2.0      0.0                                   dict_init=self.dict_init,
  1133         2            5      2.5      0.0                                   chunk_size=self.chunk_size,
  1134         2            6      3.0      0.0                                   shuffle=self.shuffle, verbose=self.verbose,
  1135         2     31390083 15695041.5    100.0                                   random_state=self.random_state)
  1136         2           15      7.5      0.0          self.components_ = U
  1137         2            4      2.0      0.0          return self

MiniBatchSparsePCA-blobs

Benchmark setup

from sklearn.decomposition import MiniBatchSparsePCA
from deps import load_data

kwargs = {'n_components': 2}
X, y, X_t, y_t = load_data('blobs')
obj = MiniBatchSparsePCA(**kwargs)

Benchmark statement

obj.fit(X)

Execution time

_images/MiniBatchSparsePCA-blobs-step0-timing.png

Memory usage

_images/MiniBatchSparsePCA-blobs-step0-memory.png

Additional output

cProfile

         29214 function calls in 0.507 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.507    0.507 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.507    0.507 <f>:1(<module>)
     1    0.000    0.000    0.507    0.507 /tmp/vb_sklearn/sklearn/decomposition/sparse_pca.py:234(fit)
     1    0.008    0.008    0.506    0.506 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:524(dict_learning_online)
   101    0.003    0.000    0.438    0.004 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:178(sparse_encode)
   101    0.011    0.000    0.409    0.004 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:24(_sparse_encode)
   364    0.313    0.001    0.392    0.001 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
  2299    0.058    0.000    0.058    0.000 {numpy.core._dotblas.dot}
   100    0.021    0.000    0.041    0.000 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:298(_update_dict)
   464    0.013    0.000    0.019    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
   367    0.005    0.000    0.014    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
   697    0.003    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
   368    0.004    0.000    0.007    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
   697    0.007    0.000    0.007    0.000 {method 'sum' of 'numpy.ndarray' objects}
   728    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
  2091    0.005    0.000    0.005    0.000 {sklearn.utils.arrayfuncs.min_pos}
   728    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
  1061    0.004    0.000    0.004    0.000 {min}
  1370    0.004    0.000    0.004    0.000 {isinstance}
  2020    0.004    0.000    0.004    0.000 {method 'get' of 'dict' objects}
   202    0.002    0.000    0.004    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2036(seterr)
  2025    0.004    0.000    0.004    0.000 {getattr}
   728    0.003    0.000    0.003    0.000 {method 'argmax' of 'numpy.ndarray' objects}
   729    0.003    0.000    0.003    0.000 {method 'copy' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
   510    0.003    0.000    0.003    0.000 {numpy.core.multiarray.array}
   829    0.003    0.000    0.003    0.000 {numpy.core.multiarray.empty}
   697    0.003    0.000    0.003    0.000 {sklearn.utils.arrayfuncs.solve_triangular}
   730    0.002    0.000    0.002    0.000 {numpy.core.multiarray.zeros}
   100    0.000    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
   408    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
  1161    0.002    0.000    0.002    0.000 {max}
     1    0.000    0.000    0.002    0.002 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
   368    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
   366    0.002    0.000    0.002    0.000 {numpy.core.multiarray.arange}
   202    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2132(geterr)
  2276    0.001    0.000    0.001    0.000 {method 'append' of 'list' objects}
   104    0.001    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
   742    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:356(array_split)
     2    0.000    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:348(_replace_zero_by_x_arrays)
   471    0.001    0.000    0.001    0.000 {range}
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
   736    0.001    0.000    0.001    0.000 {issubclass}
   368    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
   202    0.001    0.000    0.001    0.000 {numpy.core.umath.seterrobj}
     1    0.000    0.000    0.000    0.000 {method 'shuffle' of 'mtrand.RandomState' objects}
   368    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
   404    0.000    0.000    0.000    0.000 {numpy.core.umath.geterrobj}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   200    0.000    0.000    0.000    0.000 {math.sqrt}
   490    0.000    0.000    0.000    0.000 {len}
    20    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1474(sometrue)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
   101    0.000    0.000    0.000    0.000 {time.time}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
    17    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:397(swapaxes)
    32    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1211(shape)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
    17    0.000    0.000    0.000    0.000 {method 'swapaxes' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 {method 'cumsum' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:289(ascontiguousarray)
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 {hasattr}
     2    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {divmod}
     1    0.000    0.000    0.000    0.000 {math.floor}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358                                                   if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360                                                       return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/sparse_pca.py
Function: fit at line 234
Total time: 0.854349 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   234                                               def fit(self, X, y=None):
   235                                                   """Fit the model from data in X.
   236
   237                                                   Parameters
   238                                                   ----------
   239                                                   X: array-like, shape (n_samples, n_features)
   240                                                       Training vector, where n_samples in the number of samples
   241                                                       and n_features is the number of features.
   242
   243                                                   Returns
   244                                                   -------
   245                                                   self : object
   246                                                       Returns the instance itself.
   247                                                   """
   248         1           10     10.0      0.0          self.random_state = check_random_state(self.random_state)
   249         1           12     12.0      0.0          X = np.asarray(X)
   250         1            4      4.0      0.0          if self.n_components is None:
   251                                                       n_components = X.shape[1]
   252                                                   else:
   253         1            2      2.0      0.0              n_components = self.n_components
   254         1            6      6.0      0.0          Vt, _ = dict_learning_online(X.T, n_components, alpha=self.alpha,
   255         1            2      2.0      0.0                                       n_iter=self.n_iter, return_code=True,
   256         1            2      2.0      0.0                                       dict_init=None, verbose=self.verbose,
   257         1            2      2.0      0.0                                       callback=self.callback,
   258         1            3      3.0      0.0                                       chunk_size=self.chunk_size,
   259         1            2      2.0      0.0                                       shuffle=self.shuffle,
   260         1            3      3.0      0.0                                       n_jobs=self.n_jobs, method=self.method,
   261         1       854293 854293.0    100.0                                       random_state=self.random_state)
   262         1            6      6.0      0.0          self.components_ = Vt.T
   263         1            2      2.0      0.0          return self

Benchmark statement

obj.fit_transform(X)

Execution time

_images/MiniBatchSparsePCA-blobs-step1-timing.png

Memory usage

_images/MiniBatchSparsePCA-blobs-step1-memory.png

Additional output

cProfile

         29330 function calls in 0.508 seconds

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000    0.508    0.508 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
     1    0.000    0.000    0.508    0.508 <f>:1(<module>)
     1    0.000    0.000    0.508    0.508 /tmp/vb_sklearn/sklearn/base.py:332(fit_transform)
     1    0.000    0.000    0.508    0.508 /tmp/vb_sklearn/sklearn/decomposition/sparse_pca.py:234(fit)
     1    0.008    0.008    0.507    0.507 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:524(dict_learning_online)
   101    0.003    0.000    0.440    0.004 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:178(sparse_encode)
   101    0.011    0.000    0.411    0.004 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:24(_sparse_encode)
   364    0.314    0.001    0.394    0.001 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
  2313    0.058    0.000    0.058    0.000 {numpy.core._dotblas.dot}
   100    0.021    0.000    0.041    0.000 /tmp/vb_sklearn/sklearn/decomposition/dict_learning.py:298(_update_dict)
   464    0.013    0.000    0.019    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
   368    0.005    0.000    0.015    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
   703    0.003    0.000    0.012    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
   369    0.004    0.000    0.008    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
   704    0.007    0.000    0.007    0.000 {method 'sum' of 'numpy.ndarray' objects}
  2109    0.006    0.000    0.006    0.000 {sklearn.utils.arrayfuncs.min_pos}
   728    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
   728    0.002    0.000    0.005    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
  1067    0.004    0.000    0.004    0.000 {min}
  1379    0.004    0.000    0.004    0.000 {isinstance}
   202    0.001    0.000    0.003    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2036(seterr)
  2026    0.003    0.000    0.003    0.000 {getattr}
  2020    0.003    0.000    0.003    0.000 {method 'get' of 'dict' objects}
   728    0.003    0.000    0.003    0.000 {method 'argmax' of 'numpy.ndarray' objects}
   512    0.003    0.000    0.003    0.000 {numpy.core.multiarray.array}
   729    0.003    0.000    0.003    0.000 {method 'copy' of 'numpy.ndarray' objects}
   829    0.003    0.000    0.003    0.000 {numpy.core.multiarray.empty}
   703    0.003    0.000    0.003    0.000 {sklearn.utils.arrayfuncs.solve_triangular}
     1    0.000    0.000    0.003    0.003 /tmp/vb_sklearn/sklearn/utils/extmath.py:129(randomized_svd)
   100    0.000    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
   730    0.002    0.000    0.002    0.000 {numpy.core.multiarray.zeros}
  1167    0.002    0.000    0.002    0.000 {max}
   410    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
   370    0.001    0.000    0.002    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
   366    0.002    0.000    0.002    0.000 {numpy.core.multiarray.arange}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:82(randomized_range_finder)
   202    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:2132(geterr)
   104    0.001    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:181(check_random_state)
  2285    0.001    0.000    0.001    0.000 {method 'append' of 'list' objects}
   744    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:356(array_split)
   472    0.001    0.000    0.001    0.000 {range}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/utils/fixes.py:145(qr_economic)
     2    0.000    0.000    0.001    0.000 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_qr.py:16(qr)
     1    0.001    0.001    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/shape_base.py:348(_replace_zero_by_x_arrays)
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/decomposition/sparse_pca.py:123(transform)
   369    0.001    0.000    0.001    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
     1    0.000    0.000    0.001    0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
   740    0.001    0.000    0.001    0.000 {issubclass}
     1    0.000    0.000    0.001    0.001 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:55(ridge_regression)
   202    0.000    0.000    0.000    0.000 {numpy.core.umath.seterrobj}
   369    0.000    0.000    0.000    0.000 {method 'sort' of 'list' objects}
     1    0.000    0.000    0.000    0.000 {method 'shuffle' of 'mtrand.RandomState' objects}
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
   404    0.000    0.000    0.000    0.000 {numpy.core.umath.geterrobj}
   492    0.000    0.000    0.000    0.000 {len}
   200    0.000    0.000    0.000    0.000 {math.sqrt}
     1    0.000    0.000    0.000    0.000 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:23(_solve)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:19(solve)
    24    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}
    16    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1474(sometrue)
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:98(triu)
     1    0.000    0.000    0.000    0.000 {method 'normal' of 'mtrand.RandomState' objects}
     1    0.000    0.000    0.000    0.000 {map}
   101    0.000    0.000    0.000    0.000 {time.time}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/special_matrices.py:20(tri)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
     4    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
    17    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:397(swapaxes)
     1    0.000    0.000    0.000    0.000 {method 'outer' of 'numpy.ufunc' objects}
    32    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1211(shape)
     2    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.generic' objects}
     3    0.000    0.000    0.000    0.000 {hasattr}
     1    0.000    0.000    0.000    0.000 {method 'cumsum' of 'numpy.ndarray' objects}
    17    0.000    0.000    0.000    0.000 {method 'swapaxes' of 'numpy.ndarray' objects}
     1    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:289(ascontiguousarray)
     1    0.000    0.000    0.000    0.000 {method 'astype' of 'numpy.ndarray' objects}
     3    0.000    0.000    0.000    0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
     1    0.000    0.000    0.000    0.000 {divmod}
     1    0.000    0.000    0.000    0.000 {math.floor}
     1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

LineProfiler

   Timer unit: 1e-06 s

File: /tmp/vb_sklearn/sklearn/base.py
Function: fit_transform at line 332
Total time: 0.871379 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   332                                               def fit_transform(self, X, y=None, **fit_params):
   333                                                   """Fit to data, then transform it
   334
   335                                                   Fits transformer to X and y with optional parameters fit_params
   336                                                   and returns a transformed version of X.
   337
   338                                                   Parameters
   339                                                   ----------
   340                                                   X : numpy array of shape [n_samples, n_features]
   341                                                       Training set.
   342
   343                                                   y : numpy array of shape [n_samples]
   344                                                       Target values.
   345
   346                                                   Returns
   347                                                   -------
   348                                                   X_new : numpy array of shape [n_samples, n_features_new]
   349                                                       Transformed array.
   350
   351                                                   Notes
   352                                                   -----
   353                                                   This method just calls fit and transform consecutively, i.e., it is not
   354                                                   an optimized implementation of fit_transform, unlike other transformers
   355                                                   such as PCA.
   356
   357                                                   """
   358         1            3      3.0      0.0          if y is None:
   359                                                       # fit method of arity 1 (unsupervised transformation)
   360         1       871376 871376.0    100.0              return self.fit(X, **fit_params).transform(X)
   361                                                   else:
   362                                                       # fit method of arity 2 (supervised transformation)
   363                                                       return self.fit(X, y, **fit_params).transform(X)

File: /tmp/vb_sklearn/sklearn/decomposition/sparse_pca.py
Function: fit at line 234
Total time: 1.72497 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   234                                               def fit(self, X, y=None):
   235                                                   """Fit the model from data in X.
   236
   237                                                   Parameters
   238                                                   ----------
   239                                                   X: array-like, shape (n_samples, n_features)
   240                                                       Training vector, where n_samples in the number of samples
   241                                                       and n_features is the number of features.
   242
   243                                                   Returns
   244                                                   -------
   245                                                   self : object
   246                                                       Returns the instance itself.
   247                                                   """
   248         2           27     13.5      0.0          self.random_state = check_random_state(self.random_state)
   249         2           25     12.5      0.0          X = np.asarray(X)
   250         2            8      4.0      0.0          if self.n_components is None:
   251                                                       n_components = X.shape[1]
   252                                                   else:
   253         2            4      2.0      0.0              n_components = self.n_components
   254         2           12      6.0      0.0          Vt, _ = dict_learning_online(X.T, n_components, alpha=self.alpha,
   255         2            5      2.5      0.0                                       n_iter=self.n_iter, return_code=True,
   256         2            4      2.0      0.0                                       dict_init=None, verbose=self.verbose,
   257         2            4      2.0      0.0                                       callback=self.callback,
   258         2            6      3.0      0.0                                       chunk_size=self.chunk_size,
   259         2            5      2.5      0.0                                       shuffle=self.shuffle,
   260         2            6      3.0      0.0                                       n_jobs=self.n_jobs, method=self.method,
   261         2      1724850 862425.0    100.0                                       random_state=self.random_state)
   262         2           13      6.5      0.0          self.components_ = Vt.T
   263         2            5      2.5      0.0          return self
Previous
Next