scm2cpp-lasso 0.5.0__tar.gz → 0.5.2__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.
Files changed (19) hide show
  1. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/PKG-INFO +33 -4
  2. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/README.md +32 -3
  3. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/pyproject.toml +1 -1
  4. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/__init__.py +12 -1
  5. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso.egg-info/PKG-INFO +33 -4
  6. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/setup.cfg +0 -0
  7. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/setup.py +0 -0
  8. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/__init__.py +0 -0
  9. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/_loader.py +0 -0
  10. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/lasso_cov.cpp +0 -0
  11. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/lasso_cov.hpp +0 -0
  12. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/lasso_cov_capi.cpp +0 -0
  13. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_generated/scm2cpp.hpp +0 -0
  14. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/_libfind.py +0 -0
  15. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso/batch_capi.cu +0 -0
  16. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso.egg-info/SOURCES.txt +0 -0
  17. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso.egg-info/dependency_links.txt +0 -0
  18. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso.egg-info/requires.txt +0 -0
  19. {scm2cpp_lasso-0.5.0 → scm2cpp_lasso-0.5.2}/src/scm2cpp_lasso.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scm2cpp-lasso
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Lasso by covariance-update coordinate descent, translated from Scheme to C++ by scm2cpp; GPU batch solver included
5
5
  Author: Hirotaka Niitsuma
6
6
  License: MIT
@@ -32,13 +32,42 @@ Installing needs a C++17 compiler and nothing else. If `nvcc` is on
32
32
  the path, the batched GPU solver is built as well; if it is not, the
33
33
  package installs and works exactly the same, minus that one method.
34
34
 
35
+ Three of a hundred candidate columns carry the signal; the solver is
36
+ asked which, and answers with them and nothing else:
37
+
35
38
  ```python
36
39
  import numpy as np
37
- from scm2cpp_lasso import CovLasso, cuda_available
40
+ from scm2cpp_lasso import CovLasso
38
41
 
39
- model = CovLasso(X, y) # forms X'X and X'y
40
- lambdas = model.lambda_grid(num=100) # from lambda_max down
42
+ rng = np.random.default_rng(0)
43
+ X = rng.standard_normal((500, 100)) # 500 rows, 100 candidates
44
+ beta = np.zeros(100)
45
+ beta[[7, 23, 61]] = [2.0, -1.5, 0.8] # only three of them matter
46
+ y = X @ beta + 0.1 * rng.standard_normal(500)
41
47
 
48
+ model = CovLasso(X, y) # the Gram matrix, built once
49
+ path = model.fit_path(model.lambda_grid()) # 100 lambdas, warm-started
50
+
51
+ fit = path[60]
52
+ for j in np.flatnonzero(np.abs(fit) > 1e-6):
53
+ print(f" x{j:<3} {fit[j]:+.3f}")
54
+ ```
55
+
56
+ ```console
57
+ x7 +1.965
58
+ x23 -1.474
59
+ x61 +0.770
60
+ ```
61
+
62
+ The other 97 are exactly zero -- that is what the penalty is for -- and
63
+ the coefficients are the planted ones, shrunk toward zero by it.
64
+
65
+ The rest of the interface:
66
+
67
+ ```python
68
+ from scm2cpp_lasso import cuda_available
69
+
70
+ lambdas = model.lambda_grid(num=100) # from lambda_max down
42
71
  path = model.fit_path(lambdas) # warm-started, sequential
43
72
  grid = model.fit_path_batch(lambdas) # every lambda from zero
44
73
  print("GPU:", cuda_available())
@@ -14,13 +14,42 @@ Installing needs a C++17 compiler and nothing else. If `nvcc` is on
14
14
  the path, the batched GPU solver is built as well; if it is not, the
15
15
  package installs and works exactly the same, minus that one method.
16
16
 
17
+ Three of a hundred candidate columns carry the signal; the solver is
18
+ asked which, and answers with them and nothing else:
19
+
17
20
  ```python
18
21
  import numpy as np
19
- from scm2cpp_lasso import CovLasso, cuda_available
22
+ from scm2cpp_lasso import CovLasso
20
23
 
21
- model = CovLasso(X, y) # forms X'X and X'y
22
- lambdas = model.lambda_grid(num=100) # from lambda_max down
24
+ rng = np.random.default_rng(0)
25
+ X = rng.standard_normal((500, 100)) # 500 rows, 100 candidates
26
+ beta = np.zeros(100)
27
+ beta[[7, 23, 61]] = [2.0, -1.5, 0.8] # only three of them matter
28
+ y = X @ beta + 0.1 * rng.standard_normal(500)
23
29
 
30
+ model = CovLasso(X, y) # the Gram matrix, built once
31
+ path = model.fit_path(model.lambda_grid()) # 100 lambdas, warm-started
32
+
33
+ fit = path[60]
34
+ for j in np.flatnonzero(np.abs(fit) > 1e-6):
35
+ print(f" x{j:<3} {fit[j]:+.3f}")
36
+ ```
37
+
38
+ ```console
39
+ x7 +1.965
40
+ x23 -1.474
41
+ x61 +0.770
42
+ ```
43
+
44
+ The other 97 are exactly zero -- that is what the penalty is for -- and
45
+ the coefficients are the planted ones, shrunk toward zero by it.
46
+
47
+ The rest of the interface:
48
+
49
+ ```python
50
+ from scm2cpp_lasso import cuda_available
51
+
52
+ lambdas = model.lambda_grid(num=100) # from lambda_max down
24
53
  path = model.fit_path(lambdas) # warm-started, sequential
25
54
  grid = model.fit_path_batch(lambdas) # every lambda from zero
26
55
  print("GPU:", cuda_available())
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "scm2cpp-lasso"
7
- version = "0.5.0"
7
+ version = "0.5.2"
8
8
  description = "Lasso by covariance-update coordinate descent, translated from Scheme to C++ by scm2cpp; GPU batch solver included"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -31,7 +31,7 @@ from ._libfind import load_batch_lib
31
31
 
32
32
  __all__ = ["CovLasso", "CovRidge", "CovLogistic", "CovGroupLasso",
33
33
  "cuda_available", "kernel"]
34
- __version__ = "0.5.0"
34
+ __version__ = "0.5.2"
35
35
 
36
36
  _BATCH = load_batch_lib()
37
37
  _DP = ctypes.POINTER(ctypes.c_double)
@@ -141,6 +141,17 @@ class CovLasso:
141
141
 
142
142
  # ---------------------------- fitting ----------------------------
143
143
 
144
+ def fit(self, lam, **kw):
145
+ """Coefficients at one lambda.
146
+
147
+ A single penalty is the one-element special case of the path:
148
+ the Gram matrix was built in the constructor, so this costs one
149
+ descent and nothing per row -- and a warm-started path over a
150
+ whole grid costs barely more, which is why fit_path is the
151
+ primary interface rather than this convenience.
152
+ """
153
+ return self.fit_path([lam], **kw)[0]
154
+
144
155
  def fit_path(self, lambdas, tol=1e-8, chunk=20, max_sweeps=100000,
145
156
  l1_ratio=1.0):
146
157
  """Coefficients per lambda, each warm-started from the last.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scm2cpp-lasso
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Lasso by covariance-update coordinate descent, translated from Scheme to C++ by scm2cpp; GPU batch solver included
5
5
  Author: Hirotaka Niitsuma
6
6
  License: MIT
@@ -32,13 +32,42 @@ Installing needs a C++17 compiler and nothing else. If `nvcc` is on
32
32
  the path, the batched GPU solver is built as well; if it is not, the
33
33
  package installs and works exactly the same, minus that one method.
34
34
 
35
+ Three of a hundred candidate columns carry the signal; the solver is
36
+ asked which, and answers with them and nothing else:
37
+
35
38
  ```python
36
39
  import numpy as np
37
- from scm2cpp_lasso import CovLasso, cuda_available
40
+ from scm2cpp_lasso import CovLasso
38
41
 
39
- model = CovLasso(X, y) # forms X'X and X'y
40
- lambdas = model.lambda_grid(num=100) # from lambda_max down
42
+ rng = np.random.default_rng(0)
43
+ X = rng.standard_normal((500, 100)) # 500 rows, 100 candidates
44
+ beta = np.zeros(100)
45
+ beta[[7, 23, 61]] = [2.0, -1.5, 0.8] # only three of them matter
46
+ y = X @ beta + 0.1 * rng.standard_normal(500)
41
47
 
48
+ model = CovLasso(X, y) # the Gram matrix, built once
49
+ path = model.fit_path(model.lambda_grid()) # 100 lambdas, warm-started
50
+
51
+ fit = path[60]
52
+ for j in np.flatnonzero(np.abs(fit) > 1e-6):
53
+ print(f" x{j:<3} {fit[j]:+.3f}")
54
+ ```
55
+
56
+ ```console
57
+ x7 +1.965
58
+ x23 -1.474
59
+ x61 +0.770
60
+ ```
61
+
62
+ The other 97 are exactly zero -- that is what the penalty is for -- and
63
+ the coefficients are the planted ones, shrunk toward zero by it.
64
+
65
+ The rest of the interface:
66
+
67
+ ```python
68
+ from scm2cpp_lasso import cuda_available
69
+
70
+ lambdas = model.lambda_grid(num=100) # from lambda_max down
42
71
  path = model.fit_path(lambdas) # warm-started, sequential
43
72
  grid = model.fit_path_batch(lambdas) # every lambda from zero
44
73
  print("GPU:", cuda_available())
File without changes
File without changes