Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
- "--features serde"
- "--features datasets"
- "--features ndarray-bindings"
- "--features lazy-normalization"
- "--features lazy-normalization,ndarray-bindings"
- ""
steps:
- uses: actions/checkout@v4
Expand All @@ -73,7 +75,7 @@ jobs:
- name: Stable Build
run: cargo build --no-default-features ${{ matrix.features }}
- name: Tests
if: matrix.features == '--features ndarray-bindings'
if: matrix.features == '--features ndarray-bindings' || contains(matrix.features, 'lazy-normalization')
run: cargo test --no-default-features ${{ matrix.features }}

msrv:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Optional `lazy-normalization` support for Lasso and Elastic Net. It applies normalization to a borrowed design and keeps Elastic Net's identity-block augmentation implicit, while retaining the dense Gram workspace. Enable the feature and set `with_lazy_normalization(true)` to select this path. The default remains eager. The new parameter field is available only with the feature and defaults to false during deserialization (#479).

### Changed
- **Breaking change:** Enabling `lazy-normalization` adds a public `lazy_normalization` field to `LassoParameters`, `LassoSearchParameters`, `ElasticNetParameters`, and `ElasticNetSearchParameters`. Struct literals without `..Default::default()` must add `lazy_normalization: false` to retain the eager path, or `true` to select the lazy path. This also applies when another dependency enables the feature through Cargo feature unification (#479).

## [0.6.16]
### Fixed
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exclude = [
[dependencies]
approx = "0.5.1"
cfg-if = "1.0.0"
lazymatrix = { version = "0.6.0", optional = true, default-features = false }
ndarray = { version = "0.17", optional = true }
num-traits = "0.2.12"
num = "0.4"
Expand All @@ -46,6 +47,9 @@ serde = ["dep:serde", "dep:typetag"]
# Optional bindings for the ndarray crate (DenseMatrix <-> ndarray).
ndarray-bindings = ["dep:ndarray"]

# Apply Lasso and Elastic Net normalization without copying the design matrix.
lazy-normalization = ["dep:lazymatrix"]

# Sample datasets (iris, boston, digits, ...) and dataset generators.
# Enables std_rand and serde because datasets ship serialized bundles.
datasets = ["std_rand", "serde"]
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ smartcore organizes algorithms into clear modules with consistent traits:

Recent refactors emphasize reusable components in trees/forests and expanded multiclass SVM capabilities. XGBoost-style regression and single-linkage clustering have been added. See CHANGELOG for API changes and migration notes.

## Optional lazy normalization

The optional `lazy-normalization` feature lets Lasso and Elastic Net borrow the
design matrix during normalization. Elastic Net also applies its identity-block
augmentation without storing the augmented design. Enable it with `features =
["lazy-normalization"]`, then select it with
`LassoParameters::default().with_lazy_normalization(true)` or
`ElasticNetParameters::default().with_lazy_normalization(true)`. The default
remains eager, even when the feature is enabled. The `normalize` option still
controls whether columns are centered and scaled. Parameter searches use the
fixed `lazy_normalization` setting. It works with `DenseMatrix` and
`ndarray-bindings`.

Lazy normalization reduces memory use by computing normalized values when the
solver needs them. This adds repeated arithmetic and can increase fit time for
both estimators, including Elastic Net on large inputs. The solver still stores
a dense Gram matrix with one row and column per feature.

Enabling the feature adds a public `lazy_normalization` field to both estimators'
parameter and search parameter structs. Code that constructs these structs
without `..Default::default()` must add the field. Missing fields default to
`false` during deserialization.

## Data access and readers

- CSV readers: Read matrices from CSV with configurable delimiter and header rows, with helpful error messages and testing utilities (including non-IO reader abstractions).
Expand Down
Loading
Loading