sparse_coding(1) sparse coding


sparse_coding [-h] [-v] -k int -i string [-c string] [-d string] [-D string] [-l double] [-L double] [-n int] [-w double] [-N] [-o double] [-s int] -V


An implementation of Sparse Coding with Dictionary Learning, which achieves sparsity via an l1-norm regularizer on the codes (LASSO) or an (l1+l2)-norm regularizer on the codes (the Elastic Net). Given a dense data matrix X with n points and d dimensions, sparse coding seeks to find a dense dictionary matrix D with k atoms in d dimensions, and a sparse coding matrix Z with n points in k dimensions.

The original data matrix X can then be reconstructed as D * Z. Therefore, this program finds a representation of each point in X as a sparse linear combination of atoms in the dictionary D.

The sparse coding is found with an algorithm which alternates between a dictionary step, which updates the dictionary D, and a sparse coding step, which updates the sparse coding matrix.

To run this program, the input matrix X must be specified (with -i), along with the number of atoms in the dictionary (-k). An initial dictionary may also be specified with the --initial_dictionary option. The l1 and l2 norm regularization parameters may be specified with -l and -L, respectively. For example, to run sparse coding on the dataset in data.csv using 200 atoms and an l1-regularization parameter of 0.1, saving the dictionary into dict.csv and the codes into codes.csv, use

$ sparse_coding -i data.csv -k 200 -l 0.1 -d dict.csv -c codes.csv

The maximum number of iterations may be specified with the -n option. Optionally, the input data matrix X can be normalized before coding with the -N option.


--atoms (-k) [int]
Number of atoms in the dictionary.
--input_file (-i) [string]
Filename of the input data.


--codes_file (-c) [string]
Filename to save the output sparse codes to. Default value 'codes.csv'.
--dictionary_file (-d) [string]
Filename to save the output dictionary to. Default value 'dictionary.csv'.
--help (-h)
Default help info.
--info [string]
Get help on a specific module or option. Default value ''.
--initial_dictionary (-D) [string]
Filename for optional initial dictionary. Default value ''.
--lambda1 (-l) [double]
Sparse coding l1-norm regularization parameter. Default value 0.
--lambda2 (-L) [double]
Sparse coding l2-norm regularization parameter. Default value 0.
--max_iterations (-n) [int]
Maximum number of iterations for sparse coding (0 indicates no limit). Default value 0.
--newton_tolerance (-w) [double]
Tolerance for convergence of Newton method. Default value 1e-06.
--normalize (-N)
If set, the input data matrix will be normalized before coding.
--objective_tolerance (-o) [double]
Tolerance for convergence of the objective function. Default value 0.01.
--seed (-s) [int]
Random seed. If 0, 'std::time(NULL)' is used. Default value 0.
--verbose (-v)
Display informational messages and the full list of parameters and timers at the end of execution.
--version (-V)
Display the version of mlpack.


For further information, including relevant papers, citations, and theory, consult the documentation found at or included with your distribution of MLPACK.