Class: SparseCoder

Sparse coding.

Finds a sparse representation of data against a fixed, precomputed dictionary.

Each row of the result is the solution to a sparse coding problem. The goal is to find a sparse array code such that:

Python Reference

Constructors

new SparseCoder()

new SparseCoder(opts?): SparseCoder

Parameters

ParameterTypeDescription
opts?object-
opts.dictionary?ArrayLike[]The dictionary atoms used for sparse coding. Lines are assumed to be normalized to unit norm.
opts.n_jobs?numberNumber of parallel jobs to run. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details.
opts.positive_code?booleanWhether to enforce positivity when finding the code.
opts.split_sign?booleanWhether to split the sparse feature vector into the concatenation of its negative part and its positive part. This can improve the performance of downstream classifiers.
opts.transform_algorithm?"threshold" | "lars" | "lasso_lars" | "lasso_cd" | "omp"Algorithm used to transform the data:
opts.transform_alpha?numberIf algorithm='lasso_lars' or algorithm='lasso_cd', alpha is the penalty applied to the L1 norm. If algorithm='threshold', alpha is the absolute value of the threshold below which coefficients will be squashed to zero. If algorithm='omp', alpha is the tolerance parameter: the value of the reconstruction error targeted. In this case, it overrides n_nonzero_coefs. If undefined, default to 1.
opts.transform_max_iter?numberMaximum number of iterations to perform if algorithm='lasso_cd' or lasso_lars.
opts.transform_n_nonzero_coefs?numberNumber of nonzero coefficients to target in each column of the solution. This is only used by algorithm='lars' and algorithm='omp' and is overridden by alpha in the omp case. If undefined, then transform_n_nonzero_coefs=int(n_features / 10).

Returns SparseCoder

Defined in generated/decomposition/SparseCoder.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/decomposition/SparseCoder.ts:23
_isInitializedbooleanfalsegenerated/decomposition/SparseCoder.ts:22
_pyPythonBridgeundefinedgenerated/decomposition/SparseCoder.ts:21
idstringundefinedgenerated/decomposition/SparseCoder.ts:18
optsanyundefinedgenerated/decomposition/SparseCoder.ts:19

Accessors

feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/decomposition/SparseCoder.ts:380


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/decomposition/SparseCoder.ts:83

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/decomposition/SparseCoder.ts:135


fit()

fit(opts): Promise<any>

Do nothing and return the estimator unchanged.

This method is just there to implement the usual API and hence work in pipelines.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyNot used, present for API consistency by convention.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/decomposition/SparseCoder.ts:154


fit_transform()

fit_transform(opts): Promise<any[]>

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/decomposition/SparseCoder.ts:193


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: \["class_name0", "class_name1", "class_name2"\].

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly used to validate feature names with the names seen in fit.

Returns Promise<any>

Defined in generated/decomposition/SparseCoder.ts:237


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/decomposition/SparseCoder.ts:273


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/decomposition/SparseCoder.ts:96


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/decomposition/SparseCoder.ts:309


transform()

transform(opts): Promise<ArrayLike[]>

Encode the data as a sparse combination of the dictionary atoms.

Coding method is determined by the object parameter transform_algorithm.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]Training vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/SparseCoder.ts:343