MLLpNormScaler: Lp-Norm Scaler

MLLpNormScalerR Documentation

Lp-Norm Scaler

Description

Scales input features to unit norm based on the chosen L1 or L2 formulation. The center/scale arguments follow R's scale(): the norm is computed around the applied center (around 0 when center = FALSE).

Details

The *_inplace methods mutate X directly (zero-copy) when it is a double-storage matrix; other inputs are coerced to a double matrix first, in which case the coerced copy is modified. The (modified) matrix is returned in both cases. X may also be an mmap_matrix created by mem_matrix / mem_matrix_from: the disk-backed buffer is then bound zero-copy through the same Eigen map interface and modified in place on disk. All scaler methods — including fit() — require the handle to be open in "readwrite" mode, because the scaler core binds a mutable map.

Methods

Public methods


MLLpNormScaler$new()

Initialize the MLLpNormScaler

Usage
MLLpNormScaler$new(
  norm_type = 2,
  center = TRUE,
  scale = TRUE,
  n_threads = NULL
)
Arguments
norm_type

Integer, 1 for L1 norm, 2 for L2 norm (default: 2)

center

Logical, whether to center columns to mean 0 (default: TRUE)

scale

Logical, whether to scale columns to unit Lp norm (default: TRUE)

n_threads

Integer, the thread budget of the column passes (NULL, the default: the library's default budget, trex_get_num_threads(), initially 1).


MLLpNormScaler$fit()

Compute the norm parameters.

Usage
MLLpNormScaler$fit(X, threshold = 1e-12)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode (the scaler core binds a mutable map).

threshold

Double, lower bound for the scale statistic (default: 1e-12).

Returns

Value.


MLLpNormScaler$transform_inplace()

Perform standardization in-place.

Usage
MLLpNormScaler$transform_inplace(X)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLLpNormScaler$inverse_transform_inplace()

Inverse transform to original scale.

Usage
MLLpNormScaler$inverse_transform_inplace(X)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLLpNormScaler$fit_transform_inplace()

Fit and transform in one call, like R's scale().

Usage
MLLpNormScaler$fit_transform_inplace(X, threshold = 1e-12)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

threshold

Double, lower bound for the scale statistic (default: 1e-12).

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLLpNormScaler$is_fitted()

Check if scaler is fitted.

Usage
MLLpNormScaler$is_fitted()
Returns

Value.


MLLpNormScaler$get_dropped_indices()

Get dropped (degenerate) column indices. These columns get scale factor 1 and are still centered (sklearn semantics).

Usage
MLLpNormScaler$get_dropped_indices()
Returns

Value.


MLLpNormScaler$get_centers()

Get the learned centers (column means).

Usage
MLLpNormScaler$get_centers()
Returns

Value.


MLLpNormScaler$get_scales()

Get the learned scales.

Usage
MLLpNormScaler$get_scales()
Returns

Value.


MLLpNormScaler$get_center()

Check if scaler centers data.

Usage
MLLpNormScaler$get_center()
Returns

Value.


MLLpNormScaler$get_scale()

Check if scaler scales data to unit norm.

Usage
MLLpNormScaler$get_scale()
Returns

Value.


MLLpNormScaler$get_norm_type()

Get norm type (1 for L1, 2 for L2).

Usage
MLLpNormScaler$get_norm_type()
Returns

Value.


MLLpNormScaler$save()

Save model state to file.

Usage
MLLpNormScaler$save(filename)
Arguments
filename

String path to save output.

Returns

Value.


MLLpNormScaler$load()

Load model state from file.

Usage
MLLpNormScaler$load(filename)
Arguments
filename

String path to load input from.

Returns

Value.


MLLpNormScaler$clone()

The objects of this class are cloneable with this method.

Usage
MLLpNormScaler$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other ML methods: MLElasticNet, MLElasticNetCV, MLPCA, MLRidge, MLRidgeCV, MLSVD, MLZScoreScaler, ml_agglomerative_cluster(), ml_cut_tree(), ml_distance_metric, ml_linkage_method

Examples

set.seed(1)
X <- matrix(rnorm(50 * 5), 50, 5)
scaler <- MLLpNormScaler$new(norm_type = 2)
scaler$fit(X)
X_norm <- scaler$transform_inplace(X)


TRexSelector documentation built on Nov. 20, 2026, 5:09 p.m.