scm2cpp-learn 0.21.0__tar.gz → 0.22.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/PKG-INFO +15 -2
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/README.md +14 -1
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/pyproject.toml +1 -1
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/__init__.py +117 -3
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/PKG-INFO +15 -2
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/setup.cfg +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/setup.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_compat.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/__init__.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_accel_cublas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_classifiers.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_blas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_cublas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_loops.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gpu_cuda.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gramops_blas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gramops_loops.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_blas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_cublas.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_loops.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/accel_cublas/accel.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/accel_cublas/accel.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/accel_cublas/accel_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/classifiers.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/classifiers.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/classifiers_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_blas/lasso_design.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_blas/lasso_design.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_blas/lasso_design_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_cublas/lasso_design.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_cublas/lasso_design.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_cublas/lasso_design_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_loops/lasso_design.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_loops/lasso_design.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/derived_loops/lasso_design_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gpu_cuda/gpu.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gpu_cuda/gpu.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gpu_cuda/gpu_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_blas/gramops.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_blas/gramops.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_blas/gramops_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_loops/gramops.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_loops/gramops.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_loops/gramops_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/lasso_cov.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/lasso_cov.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/lasso_cov_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_cublas/nmf_cd.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_cublas/nmf_cd.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_cublas/nmf_cd_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd_capi.cpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/scm2cpp-blas.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/scm2cpp-cublas.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/scm2cpp-cuda.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/scm2cpp.hpp +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_libfind.py +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/batch_capi.cu +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/SOURCES.txt +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/dependency_links.txt +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/requires.txt +0 -0
- {scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scm2cpp-learn
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.22.0
|
|
4
4
|
Summary: scikit-learn estimators (lasso, elastic net, ridge, RidgeCV, ARD, SVM, SVR, logistic regression, GLMs, Huber, Theil-Sen, F-score selection, RFE, NMF, Gaussian mixture, FastICA, PCA, KernelPCA, LDA, TruncatedSVD, PLS, CCA, graphical lasso, RANSAC, SGD, OMP, LARS) translated from Scheme to C++ by scm2cpp; GPU batch solver and CUDA kernels included
|
|
5
5
|
Author: Hirotaka Niitsuma
|
|
6
6
|
License: MIT
|
|
@@ -37,7 +37,7 @@ with a DeprecationWarning.
|
|
|
37
37
|
$ pip install scm2cpp-learn
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
On Linux x86_64, macOS arm64 (macOS
|
|
40
|
+
On Linux x86_64, macOS arm64 (macOS 15 or later) and Windows AMD64
|
|
41
41
|
this installs a wheel: compiled, nothing to build (with OpenBLAS
|
|
42
42
|
inside on Linux and macOS; Windows has the loop variants). Elsewhere pip builds the sdist,
|
|
43
43
|
which needs a C++17 compiler and nothing else. The wheels carry no
|
|
@@ -482,6 +482,19 @@ a stock-feature design with n=743 and p=180, 0.21 s against 145 s for
|
|
|
482
482
|
the descent on the same grid; at p=3495, 2.2 s, where the descent was
|
|
483
483
|
stopped after 30 minutes. The default stays `solver="cd"`.
|
|
484
484
|
|
|
485
|
+
`working_set=k` (with `solver="lars"`, a dense X) is for a design too
|
|
486
|
+
wide for its Gram matrix -- p by p, 309 GB at p = 196,574. Each fold
|
|
487
|
+
and the refit are solved on a working set of columns: the k most
|
|
488
|
+
correlated with y to begin with; then, while a column outside the set
|
|
489
|
+
breaks the optimality conditions at some grid point (the gradient
|
|
490
|
+
against alpha over all p columns, 1e-5 relative), the k worst of them
|
|
491
|
+
join and the set is solved again. When none does, every grid solution
|
|
492
|
+
solves the whole problem -- checked, not assumed -- so the fit is the
|
|
493
|
+
full Gram's (`check-wheel.py`: 3e-13 at p = 3000, n = 150, the set
|
|
494
|
+
staying well below p), in memory O(np) plus the set's Gram.
|
|
495
|
+
`working_set_` records the rounds and the final set's size for each
|
|
496
|
+
fold and the refit.
|
|
497
|
+
|
|
485
498
|
The elastic net cross-validates the same way: `CovLassoCV(l1_ratio=0.5)`
|
|
486
499
|
against `ElasticNetCV(l1_ratio=0.5)` on the same folds and alpha grid
|
|
487
500
|
(`bench/lasso-compare.py --cv-only --l1-ratio 0.5`, same conditions,
|
|
@@ -19,7 +19,7 @@ with a DeprecationWarning.
|
|
|
19
19
|
$ pip install scm2cpp-learn
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
On Linux x86_64, macOS arm64 (macOS
|
|
22
|
+
On Linux x86_64, macOS arm64 (macOS 15 or later) and Windows AMD64
|
|
23
23
|
this installs a wheel: compiled, nothing to build (with OpenBLAS
|
|
24
24
|
inside on Linux and macOS; Windows has the loop variants). Elsewhere pip builds the sdist,
|
|
25
25
|
which needs a C++17 compiler and nothing else. The wheels carry no
|
|
@@ -464,6 +464,19 @@ a stock-feature design with n=743 and p=180, 0.21 s against 145 s for
|
|
|
464
464
|
the descent on the same grid; at p=3495, 2.2 s, where the descent was
|
|
465
465
|
stopped after 30 minutes. The default stays `solver="cd"`.
|
|
466
466
|
|
|
467
|
+
`working_set=k` (with `solver="lars"`, a dense X) is for a design too
|
|
468
|
+
wide for its Gram matrix -- p by p, 309 GB at p = 196,574. Each fold
|
|
469
|
+
and the refit are solved on a working set of columns: the k most
|
|
470
|
+
correlated with y to begin with; then, while a column outside the set
|
|
471
|
+
breaks the optimality conditions at some grid point (the gradient
|
|
472
|
+
against alpha over all p columns, 1e-5 relative), the k worst of them
|
|
473
|
+
join and the set is solved again. When none does, every grid solution
|
|
474
|
+
solves the whole problem -- checked, not assumed -- so the fit is the
|
|
475
|
+
full Gram's (`check-wheel.py`: 3e-13 at p = 3000, n = 150, the set
|
|
476
|
+
staying well below p), in memory O(np) plus the set's Gram.
|
|
477
|
+
`working_set_` records the rounds and the final set's size for each
|
|
478
|
+
fold and the refit.
|
|
479
|
+
|
|
467
480
|
The elastic net cross-validates the same way: `CovLassoCV(l1_ratio=0.5)`
|
|
468
481
|
against `ElasticNetCV(l1_ratio=0.5)` on the same folds and alpha grid
|
|
469
482
|
(`bench/lasso-compare.py --cv-only --l1-ratio 0.5`, same conditions,
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scm2cpp-learn"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.22.0"
|
|
8
8
|
description = "scikit-learn estimators (lasso, elastic net, ridge, RidgeCV, ARD, SVM, SVR, logistic regression, GLMs, Huber, Theil-Sen, F-score selection, RFE, NMF, Gaussian mixture, FastICA, PCA, KernelPCA, LDA, TruncatedSVD, PLS, CCA, graphical lasso, RANSAC, SGD, OMP, LARS) translated from Scheme to C++ by scm2cpp; GPU batch solver and CUDA kernels included"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -58,7 +58,7 @@ __all__ = ["GramLasso", "GramElasticNet", "GramRidge", "GramRidgeCV", "CovLasso"
|
|
|
58
58
|
"GramLogisticRegression", "GramGroupLasso", "GramMultiTaskLasso",
|
|
59
59
|
"GramMultiTaskElasticNet", "DesignLasso",
|
|
60
60
|
"cuda_available", "derived_backend", "kernel"]
|
|
61
|
-
__version__ = "0.
|
|
61
|
+
__version__ = "0.22.0"
|
|
62
62
|
|
|
63
63
|
_BATCH = load_batch_lib()
|
|
64
64
|
_DP = ctypes.POINTER(ctypes.c_double)
|
|
@@ -601,14 +601,27 @@ class CovLassoCV(Tagged, RegressorMixin, BaseEstimator):
|
|
|
601
601
|
coordinate descent (n_polished_ counts them). The default "cd" is
|
|
602
602
|
the descent.
|
|
603
603
|
|
|
604
|
+
working_set=k (with solver="lars", a dense X) is for a design too
|
|
605
|
+
wide for its Gram matrix (p x p: 309 GB at p = 196574). Each fold,
|
|
606
|
+
and the refit, is solved on a working set of columns: first the k
|
|
607
|
+
most correlated with y; then, while a column outside the set breaks
|
|
608
|
+
the optimality conditions at some grid point (|gradient| > alpha, to
|
|
609
|
+
1e-5 relative, checked over all p columns), the k worst of them
|
|
610
|
+
join it and the set is solved again. When none does, every grid
|
|
611
|
+
solution is a solution of the whole problem -- checked, not assumed
|
|
612
|
+
-- so the fit is the one the full Gram gives, in memory O(n p) plus
|
|
613
|
+
the working set's Gram. The data is centred as a copy here. The
|
|
614
|
+
default None forms the full Gram.
|
|
615
|
+
|
|
604
616
|
Attributes after fit: alphas_, mse_path_ (num, n_folds), alpha_,
|
|
605
617
|
coef_, intercept_; with solver="lars" also n_polished_ and n_iter_ (the refit's
|
|
606
|
-
path steps)
|
|
618
|
+
path steps); with working_set also working_set_, the (rounds,
|
|
619
|
+
columns in the final set) of each fold and, last, of the refit.
|
|
607
620
|
"""
|
|
608
621
|
|
|
609
622
|
def __init__(self, cv=5, num=100, eps=1e-3, tol=1e-8, l1_ratio=1.0,
|
|
610
623
|
force_cpu=False, force_gpu=False, n_jobs=1, fit_intercept=False,
|
|
611
|
-
solver="cd"):
|
|
624
|
+
solver="cd", working_set=None):
|
|
612
625
|
# Folds are independent, the descent is a ctypes call and the
|
|
613
626
|
# products are BLAS calls, both of which release the GIL, so
|
|
614
627
|
# plain threads scale the CPU path across folds. Default 1:
|
|
@@ -617,6 +630,105 @@ class CovLassoCV(Tagged, RegressorMixin, BaseEstimator):
|
|
|
617
630
|
self.l1_ratio, self.force_cpu, self.force_gpu = l1_ratio, force_cpu, force_gpu
|
|
618
631
|
self.n_jobs, self.fit_intercept = n_jobs, fit_intercept
|
|
619
632
|
self.solver = solver
|
|
633
|
+
self.working_set = working_set
|
|
634
|
+
|
|
635
|
+
def _ws_grid(self, Xc, yc):
|
|
636
|
+
"""The lasso solutions at alphas_ (rows, p columns) for centred
|
|
637
|
+
Xc, yc by _lars_grid on a working set S of columns, with the
|
|
638
|
+
(rounds, columns of S) it took.
|
|
639
|
+
|
|
640
|
+
S starts as the working_set columns most correlated with yc.
|
|
641
|
+
After each solve the gradient Xc'(yc - Xc b)/n of every grid
|
|
642
|
+
solution is formed over all columns; a column outside S whose
|
|
643
|
+
gradient exceeds alpha (1e-5 relative, the tolerance the path
|
|
644
|
+
itself is held to) breaks the optimality conditions, and the
|
|
645
|
+
working_set worst of them join S. The loop ends when no column
|
|
646
|
+
breaks them. Columns equal up to a factor are cut by _lars_grid
|
|
647
|
+
as before; one of larger norm outside S shows up as a violation
|
|
648
|
+
and takes its copy's place."""
|
|
649
|
+
n, p = Xc.shape
|
|
650
|
+
k = int(self.working_set)
|
|
651
|
+
a = self.alphas_
|
|
652
|
+
den = np.where(a > 0, a, 1.0)
|
|
653
|
+
c = Xc.T @ yc
|
|
654
|
+
S = np.sort(np.argsort(-np.abs(c), kind="stable")[:min(k, p)])
|
|
655
|
+
rounds = 0
|
|
656
|
+
while True:
|
|
657
|
+
rounds += 1
|
|
658
|
+
XS = Xc[:, S]
|
|
659
|
+
BS, it = self._lars_grid(XS.T @ XS, c[S], n)
|
|
660
|
+
R = yc[:, None] - XS @ BS.T
|
|
661
|
+
viol = (np.abs(Xc.T @ R) / n - a[None, :]) / den[None, :]
|
|
662
|
+
viol[S] = 0.0
|
|
663
|
+
worst = viol.max(axis=1)
|
|
664
|
+
bad = np.flatnonzero(worst > 1e-5)
|
|
665
|
+
if bad.size == 0:
|
|
666
|
+
B = np.zeros((len(a), p))
|
|
667
|
+
B[:, S] = BS
|
|
668
|
+
return B, it, (rounds, int(S.size))
|
|
669
|
+
bad = bad[np.argsort(-worst[bad], kind="stable")[:k]]
|
|
670
|
+
S = np.union1d(S, bad)
|
|
671
|
+
|
|
672
|
+
def _fit_working_set(self, X, y):
|
|
673
|
+
"""fit for working_set: the same grid, folds, centring,
|
|
674
|
+
validation error, choice and refit as the full Gram's, each
|
|
675
|
+
solve by _ws_grid on a centred copy of its rows."""
|
|
676
|
+
if self.solver != "lars":
|
|
677
|
+
raise ValueError("working_set needs solver='lars'")
|
|
678
|
+
if float(self.l1_ratio) != 1.0:
|
|
679
|
+
raise ValueError("solver='lars' solves the lasso only (l1_ratio=1)")
|
|
680
|
+
if _issparse(X):
|
|
681
|
+
raise ValueError("working_set needs a dense X")
|
|
682
|
+
if int(self.working_set) < 1:
|
|
683
|
+
raise ValueError(f"working_set must be a positive number of columns, got {self.working_set!r}")
|
|
684
|
+
n, num = len(y), int(self.num)
|
|
685
|
+
fi = bool(self.fit_intercept)
|
|
686
|
+
self._lars_polished_ = 0
|
|
687
|
+
|
|
688
|
+
def centre(Xt, yt):
|
|
689
|
+
if not fi:
|
|
690
|
+
return Xt, yt, np.zeros(Xt.shape[1]), 0.0
|
|
691
|
+
xm, ym = Xt.mean(axis=0), float(yt.mean())
|
|
692
|
+
return Xt - xm, yt - ym, xm, ym
|
|
693
|
+
# all rows first: the grid starts at their lambda_max, and their
|
|
694
|
+
# solutions at the grid are the refit's, whichever alpha wins
|
|
695
|
+
Xc, yc, xm_all, ym_all = centre(X, y)
|
|
696
|
+
hi = float(np.max(np.abs(Xc.T @ yc))) / n
|
|
697
|
+
self.alphas_ = hi * np.logspace(0, np.log10(float(self.eps)), num)
|
|
698
|
+
B_all, self.n_iter_, info_all = self._ws_grid(Xc, yc)
|
|
699
|
+
del Xc, yc
|
|
700
|
+
folds = self._folds(X, y, n)
|
|
701
|
+
self.mse_path_ = np.empty((num, len(folds)))
|
|
702
|
+
info = [None] * len(folds)
|
|
703
|
+
|
|
704
|
+
def one_fold(k):
|
|
705
|
+
train, test = folds[k]
|
|
706
|
+
if train is None:
|
|
707
|
+
tr = np.ones(n, dtype=bool)
|
|
708
|
+
tr[test] = False
|
|
709
|
+
else:
|
|
710
|
+
tr = train
|
|
711
|
+
Xc, yc, xm, ym = centre(X[tr], y[tr])
|
|
712
|
+
B, _, info[k] = self._ws_grid(Xc, yc)
|
|
713
|
+
del Xc
|
|
714
|
+
resid = (X[test] - xm) @ B.T - (y[test] - ym)[:, None]
|
|
715
|
+
self.mse_path_[:, k] = np.mean(resid * resid, axis=0)
|
|
716
|
+
|
|
717
|
+
if int(self.n_jobs) > 1:
|
|
718
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
719
|
+
with ThreadPoolExecutor(max_workers=int(self.n_jobs)) as ex:
|
|
720
|
+
list(ex.map(one_fold, range(len(folds))))
|
|
721
|
+
else:
|
|
722
|
+
for k in range(len(folds)):
|
|
723
|
+
one_fold(k)
|
|
724
|
+
# alphas_ descends, so argmin's first hit is the larger penalty
|
|
725
|
+
ib = int(np.argmin(self.mse_path_.mean(axis=1)))
|
|
726
|
+
self.alpha_ = float(self.alphas_[ib])
|
|
727
|
+
self.coef_ = B_all[ib].copy()
|
|
728
|
+
self.intercept_ = ym_all - float(xm_all @ self.coef_)
|
|
729
|
+
self.n_polished_ = self._lars_polished_
|
|
730
|
+
self.working_set_ = info + [info_all]
|
|
731
|
+
return self
|
|
620
732
|
|
|
621
733
|
def _lars_grid(self, G, c, nobs):
|
|
622
734
|
"""The lasso solutions at alphas_ (rows) for Gram G and
|
|
@@ -749,6 +861,8 @@ class CovLassoCV(Tagged, RegressorMixin, BaseEstimator):
|
|
|
749
861
|
|
|
750
862
|
def fit(self, X, y):
|
|
751
863
|
X, y = fit_xy(self, X, y)
|
|
864
|
+
if self.working_set is not None:
|
|
865
|
+
return self._fit_working_set(X, y)
|
|
752
866
|
n = len(y)
|
|
753
867
|
num = int(self.num)
|
|
754
868
|
tol, l1_ratio = float(self.tol), float(self.l1_ratio)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scm2cpp-learn
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.22.0
|
|
4
4
|
Summary: scikit-learn estimators (lasso, elastic net, ridge, RidgeCV, ARD, SVM, SVR, logistic regression, GLMs, Huber, Theil-Sen, F-score selection, RFE, NMF, Gaussian mixture, FastICA, PCA, KernelPCA, LDA, TruncatedSVD, PLS, CCA, graphical lasso, RANSAC, SGD, OMP, LARS) translated from Scheme to C++ by scm2cpp; GPU batch solver and CUDA kernels included
|
|
5
5
|
Author: Hirotaka Niitsuma
|
|
6
6
|
License: MIT
|
|
@@ -37,7 +37,7 @@ with a DeprecationWarning.
|
|
|
37
37
|
$ pip install scm2cpp-learn
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
On Linux x86_64, macOS arm64 (macOS
|
|
40
|
+
On Linux x86_64, macOS arm64 (macOS 15 or later) and Windows AMD64
|
|
41
41
|
this installs a wheel: compiled, nothing to build (with OpenBLAS
|
|
42
42
|
inside on Linux and macOS; Windows has the loop variants). Elsewhere pip builds the sdist,
|
|
43
43
|
which needs a C++17 compiler and nothing else. The wheels carry no
|
|
@@ -482,6 +482,19 @@ a stock-feature design with n=743 and p=180, 0.21 s against 145 s for
|
|
|
482
482
|
the descent on the same grid; at p=3495, 2.2 s, where the descent was
|
|
483
483
|
stopped after 30 minutes. The default stays `solver="cd"`.
|
|
484
484
|
|
|
485
|
+
`working_set=k` (with `solver="lars"`, a dense X) is for a design too
|
|
486
|
+
wide for its Gram matrix -- p by p, 309 GB at p = 196,574. Each fold
|
|
487
|
+
and the refit are solved on a working set of columns: the k most
|
|
488
|
+
correlated with y to begin with; then, while a column outside the set
|
|
489
|
+
breaks the optimality conditions at some grid point (the gradient
|
|
490
|
+
against alpha over all p columns, 1e-5 relative), the k worst of them
|
|
491
|
+
join and the set is solved again. When none does, every grid solution
|
|
492
|
+
solves the whole problem -- checked, not assumed -- so the fit is the
|
|
493
|
+
full Gram's (`check-wheel.py`: 3e-13 at p = 3000, n = 150, the set
|
|
494
|
+
staying well below p), in memory O(np) plus the set's Gram.
|
|
495
|
+
`working_set_` records the rounds and the final set's size for each
|
|
496
|
+
fold and the refit.
|
|
497
|
+
|
|
485
498
|
The elastic net cross-validates the same way: `CovLassoCV(l1_ratio=0.5)`
|
|
486
499
|
against `ElasticNetCV(l1_ratio=0.5)` on the same folds and alpha grid
|
|
487
500
|
(`bench/lasso-compare.py --cv-only --l1-ratio 0.5`, same conditions,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_accel_cublas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_classifiers.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_blas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_cublas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_derived_loops.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gpu_cuda.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gramops_blas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_gramops_loops.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_blas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_cublas.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/_loader_nmf_loops.py
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/accel_cublas/accel.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/accel_cublas/accel.hpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/classifiers_capi.cpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gpu_cuda/gpu_capi.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_blas/gramops.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_blas/gramops.hpp
RENAMED
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_loops/gramops.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/gramops_loops/gramops.hpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/lasso_cov_capi.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd.hpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_blas/nmf_cd_capi.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_cublas/nmf_cd.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_cublas/nmf_cd.hpp
RENAMED
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd.cpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd.hpp
RENAMED
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/nmf_loops/nmf_cd_capi.cpp
RENAMED
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn/_generated/scm2cpp-cublas.hpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scm2cpp_learn-0.21.0 → scm2cpp_learn-0.22.0}/src/scm2cpp_learn.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|