Package mdp :: Package nodes :: Class ProjectedGradientNMFScikitsLearnNode
[hide private]
[frames] | no frames]

Class ProjectedGradientNMFScikitsLearnNode



Non-Negative Matrix Factorization (NMF)

This node has been automatically generated by wrapping the ``sklearn.decomposition.nmf.ProjectedGradientNMF`` class
from the ``sklearn`` library.  The wrapped instance can be accessed
through the ``scikits_alg`` attribute.

Find two non-negative matrices (W, H) whose product approximates the non-
negative matrix X. This factorization can be used for example for
dimensionality reduction, source separation or topic extraction.

The objective function is::


    0.5 * ||X - WH||_Fro^2
    + alpha * l1_ratio * ||vec(W)||_1
    + alpha * l1_ratio * ||vec(H)||_1
    + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2
    + 0.5 * alpha * (1 - l1_ratio) * ||H||_Fro^2

Where::


    ||A||_Fro^2 = \sum_{i,j} A_{ij}^2 (Frobenius norm)
    ||vec(A)||_1 = \sum_{i,j} abs(A_{ij}) (Elementwise L1 norm)

The objective function is minimized with an alternating minimization of W
and H.

Read more in the :ref:`User Guide <NMF>`.

**Parameters**

n_components : int or None
    Number of components, if n_components is not set all features
    are kept.

init :  'random' | 'nndsvd' |  'nndsvda' | 'nndsvdar' | 'custom'
    Method used to initialize the procedure.
    Default: 'nndsvdar' if n_components < n_features, otherwise random.
    Valid options:


    - 'random': non-negative random matrices, scaled with:

        - sqrt(X.mean() / n_components)


    - 'nndsvd': Nonnegative Double Singular Value Decomposition (NNDSVD)
        initialization (better for sparseness)

    - 'nndsvda': NNDSVD with zeros filled with the average of X
        (better when sparsity is not desired)

    - 'nndsvdar': NNDSVD with zeros filled with small random values
        (generally faster, less accurate alternative to NNDSVDa
        for when sparsity is not desired)

    - 'custom': use custom matrices W and H

solver : 'pg' | 'cd'
    Numerical solver to use:

    - 'pg' is a Projected Gradient solver (deprecated).
    - 'cd' is a Coordinate Descent solver (recommended).


    .. versionadded:: 0.17
       Coordinate Descent solver.

    .. versionchanged:: 0.17
       Deprecated Projected Gradient solver.

tol : double, default: 1e-4
    Tolerance value used in stopping conditions.

max_iter : integer, default: 200
    Number of iterations to compute.

random_state : integer seed, RandomState instance, or None (default)
    Random number generator seed control.

alpha : double, default: 0.
    Constant that multiplies the regularization terms. Set it to zero to
    have no regularization.

    .. versionadded:: 0.17
       *alpha* used in the Coordinate Descent solver.

l1_ratio : double, default: 0.
    The regularization mixing parameter, with 0 <= l1_ratio <= 1.
    For l1_ratio = 0 the penalty is an elementwise L2 penalty
    (aka Frobenius Norm).
    For l1_ratio = 1 it is an elementwise L1 penalty.
    For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

    .. versionadded:: 0.17
       Regularization parameter *l1_ratio* used in the Coordinate Descent solver.

shuffle : boolean, default: False
    If true, randomize the order of coordinates in the CD solver.

    .. versionadded:: 0.17
       *shuffle* parameter used in the Coordinate Descent solver.

nls_max_iter : integer, default: 2000
    Number of iterations in NLS subproblem.
    Used only in the deprecated 'pg' solver.

    .. versionchanged:: 0.17
       Deprecated Projected Gradient solver. Use Coordinate Descent solver
       instead.

sparseness : 'data' | 'components' | None, default: None
    Where to enforce sparsity in the model.
    Used only in the deprecated 'pg' solver.

    .. versionchanged:: 0.17
       Deprecated Projected Gradient solver. Use Coordinate Descent solver
       instead.

beta : double, default: 1
    Degree of sparseness, if sparseness is not None. Larger values mean
    more sparseness. Used only in the deprecated 'pg' solver.

    .. versionchanged:: 0.17
       Deprecated Projected Gradient solver. Use Coordinate Descent solver
       instead.

eta : double, default: 0.1
    Degree of correctness to maintain, if sparsity is not None. Smaller
    values mean larger error. Used only in the deprecated 'pg' solver.

    .. versionchanged:: 0.17
       Deprecated Projected Gradient solver. Use Coordinate Descent solver
       instead.

**Attributes**

``components_`` : array, [n_components, n_features]
    Non-negative components of the data.

``reconstruction_err_`` : number
    Frobenius norm of the matrix difference between
    the training data and the reconstructed data from
    the fit produced by the model. ``|| X - WH ||_2``

``n_iter_`` : int
    Actual number of iterations.

**Examples**

>>> import numpy as np
>>> X = np.array([[1,1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]])
>>> from sklearn.decomposition import NMF
>>> model = NMF(n_components=2, init='random', random_state=0)
>>> model.fit(X) #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
NMF(alpha=0.0, beta=1, eta=0.1, init='random', l1_ratio=0.0, max_iter=200,
  n_components=2, nls_max_iter=2000, random_state=0, shuffle=False,
  solver='cd', sparseness=None, tol=0.0001, verbose=0)

>>> model.components_
array([[ 2.09783018,  0.30560234],
       [ 2.13443044,  2.13171694]])
>>> model.reconstruction_err_ #doctest: +ELLIPSIS
0.00115993...

**References**

C.-J. Lin. Projected gradient methods for non-negative matrix
factorization. Neural Computation, 19(2007), 2756-2779.
http://www.csie.ntu.edu.tw/~cjlin/nmf/

Cichocki, Andrzej, and P. H. A. N. Anh-Huy. "Fast local algorithms for
large scale nonnegative matrix and tensor factorizations."
IEICE transactions on fundamentals of electronics, communications and
computer sciences 92.3: 708-721, 2009.

Instance Methods [hide private]
 
__init__(self, input_dim=None, output_dim=None, dtype=None, **kwargs)
This node has been automatically generated by wrapping the sklearn.decomposition.nmf.ProjectedGradientNMF class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.
 
_execute(self, x)
 
_get_supported_dtypes(self)
Return the list of dtypes supported by this node. The types can be specified in any format allowed by numpy.dtype.
 
_stop_training(self, **kwargs)
Concatenate the collected data in a single array.
 
execute(self, x)
Transform the data X according to the fitted NMF model
 
stop_training(self, **kwargs)
Learn a NMF model for the data X.

Inherited from unreachable.newobject: __long__, __native__, __nonzero__, __unicode__, next

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

    Inherited from Cumulator
 
_train(self, *args)
Collect all input data in a list.
 
train(self, *args)
Collect all input data in a list.
    Inherited from Node
 
__add__(self, other)
 
__call__(self, x, *args, **kwargs)
Calling an instance of Node is equivalent to calling its execute method.
 
__repr__(self)
repr(x)
 
__str__(self)
str(x)
 
_check_input(self, x)
 
_check_output(self, y)
 
_check_train_args(self, x, *args, **kwargs)
 
_get_train_seq(self)
 
_if_training_stop_training(self)
 
_inverse(self, x)
 
_pre_execution_checks(self, x)
This method contains all pre-execution checks.
 
_pre_inversion_checks(self, y)
This method contains all pre-inversion checks.
 
_refcast(self, x)
Helper function to cast arrays to the internal dtype.
 
_set_dtype(self, t)
 
_set_input_dim(self, n)
 
_set_output_dim(self, n)
 
copy(self, protocol=None)
Return a deep copy of the node.
 
get_current_train_phase(self)
Return the index of the current training phase.
 
get_dtype(self)
Return dtype.
 
get_input_dim(self)
Return input dimensions.
 
get_output_dim(self)
Return output dimensions.
 
get_remaining_train_phase(self)
Return the number of training phases still to accomplish.
 
get_supported_dtypes(self)
Return dtypes supported by the node as a list of dtype objects.
 
has_multiple_training_phases(self)
Return True if the node has multiple training phases.
 
inverse(self, y, *args, **kwargs)
Invert y.
 
is_training(self)
Return True if the node is in the training phase, False otherwise.
 
save(self, filename, protocol=-1)
Save a pickled serialization of the node to filename. If filename is None, return a string.
 
set_dtype(self, t)
Set internal structures' dtype.
 
set_input_dim(self, n)
Set input dimensions.
 
set_output_dim(self, n)
Set output dimensions.
Static Methods [hide private]
 
is_invertible()
Return True if the node can be inverted, False otherwise.
 
is_trainable()
Return True if the node can be trained, False otherwise.
Properties [hide private]

Inherited from object: __class__

    Inherited from Node
  _train_seq
List of tuples:
  dtype
dtype
  input_dim
Input dimensions
  output_dim
Output dimensions
  supported_dtypes
Supported dtypes
Method Details [hide private]

__init__(self, input_dim=None, output_dim=None, dtype=None, **kwargs)
(Constructor)

 
This node has been automatically generated by wrapping the sklearn.decomposition.nmf.ProjectedGradientNMF class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.
Overrides: object.__init__

_execute(self, x)

 
Overrides: Node._execute

_get_supported_dtypes(self)

 
Return the list of dtypes supported by this node. The types can be specified in any format allowed by numpy.dtype.
Overrides: Node._get_supported_dtypes

_stop_training(self, **kwargs)

 
Concatenate the collected data in a single array.
Overrides: Node._stop_training

execute(self, x)

 

Transform the data X according to the fitted NMF model

This node has been automatically generated by wrapping the sklearn.decomposition.nmf.ProjectedGradientNMF class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

Parameters

X: {array-like, sparse matrix}, shape (n_samples, n_features)
Data matrix to be transformed by the model

Attributes

n_iter_ : int
Actual number of iterations for the transform.

Returns

W: array, shape (n_samples, n_components)
Transformed data
Overrides: Node.execute

is_invertible()
Static Method

 
Return True if the node can be inverted, False otherwise.
Overrides: Node.is_invertible
(inherited documentation)

is_trainable()
Static Method

 
Return True if the node can be trained, False otherwise.
Overrides: Node.is_trainable

stop_training(self, **kwargs)

 

Learn a NMF model for the data X.

This node has been automatically generated by wrapping the sklearn.decomposition.nmf.ProjectedGradientNMF class from the sklearn library. The wrapped instance can be accessed through the scikits_alg attribute.

Parameters

X: {array-like, sparse matrix}, shape (n_samples, n_features)
Data matrix to be decomposed

Attributes

components_ : array-like, shape (n_components, n_features)
Factorization matrix, sometimes called 'dictionary'.
n_iter_ : int
Actual number of iterations for the transform.

Returns

self

Overrides: Node.stop_training