Categories &

Functions List

Function Reference: sparsefilt

statistics: Mdl = sparsefilt (X, Q)
statistics: Mdl = sparsefilt (X, Q, Name, Value)

Sparse filtering for feature extraction.

Mdl = sparsefilt (X, Q) learns Q features from the N × P data matrix X (rows are observations, columns are predictors) and returns a SparseFiltering object Mdl. Apply the learned transformation to data with transform (Mdl, X).

The N × Q features returned by transform are the soft-absolute activations sqrt ((X * W) .^ 2 + 1e-8), normalized first across observations (each feature) and then across features (each observation). The P × Q weight matrix W minimizes the sum of those features plus an L2 penalty Lambda * ||W ||_F^2, driving the features to be sparse.

Name/Value pairs:

'IterationLimit'
Maximum number of iterations (default 1000).
'Lambda'
Weight of the L2 penalty on the transform weights (default 1).
'Standardize'
Logical; center and scale each predictor before fitting (default false).
'InitialTransformWeights'
A P × Q initial value for the weights. The default is random.
'GradientTolerance', 'StepTolerance'
Stop once the gradient’s or the step’s infinity norm falls to or below the given value (default 1e-6 each). They govern the fit only under 'Solver', 'lbfgs'; the 'quasinewton' solver runs to its own tighter internal tolerances and records these without acting on them.
'Solver'
'quasinewton' (default) minimizes through Octave’s fminunc, which carries a full inverse Hessian. 'lbfgs' selects the limited-memory BFGS solver MATLAB uses, holding as many curvature pairs as the transform has parameters, and is several times faster here. It stops where 'GradientTolerance' and 'StepTolerance' say to, so a value tighter than the default carries it further.

Note on reproducibility

The sparse filtering objective is not convex and is minimized by a quasi-Newton solver, so the learned weights depend on the starting point and the solver. Different runs (or different software, including MATLAB) may return different weights that nonetheless describe an equally valid feature transformation. Fix 'InitialTransformWeights' for a reproducible result.

See also: SparseFiltering, rica, pca

Source Code: sparsefilt

Learn two sparse features from data with the default (random) start.

 X = [1, 2, 3, 4; 2, 3, 4, 5; -1, 0, 1, 2; 3, 1, 4, 1; 0, 2, 1, 3];
 Mdl = sparsefilt (X, 2, "IterationLimit", 200);
 Z = transform (Mdl, X)
Z =

   9.9999e-01   3.9702e-03
   9.9999e-01   3.6437e-03
   9.9999e-01   4.8378e-03
   9.2406e-04   1.0000e+00
   9.9999e-01   5.1560e-03