pytmpinv 1.0.0__tar.gz → 1.0.1__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.

Potentially problematic release.


This version of pytmpinv might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytmpinv
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Tabular Matrix Problems via Pseudoinverse Estimation
5
5
  Author-email: The Economist <29724411+econcz@users.noreply.github.com>
6
6
  License-Expression: MIT
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
 
24
24
  # Tabular Matrix Problems via Pseudoinverse Estimation
25
25
 
26
- The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net).
26
+ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net). All calculations are performed in numpy.float64 precision.
27
27
 
28
28
  ## Installation
29
29
 
@@ -137,11 +137,14 @@ A symmetric idempotent matrix (projector) defining the subspace for Bott–Duffi
137
137
  `final` : *bool*, default = *True*
138
138
  If *True*, a convex programming problem is solved to refine `zhat`. The resulting solution `z` minimizes a weighted L1/L2 norm around `zhat` subject to `Az = b`.
139
139
 
140
- `alpha` : *float*, default = *1.0*
141
- Regularization parameter (weight) in the final convex program:
142
- - `α = 0`: Lasso (L1 norm)
143
- - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
144
- - `0 < α < 1`: Elastic Net
140
+ `alpha` : *float*, *list[float]* or *None*, default = *None*
141
+ Regularization parameter (weight) in the final convex program:
142
+ - `α = 0`: Lasso (L1 norm)
143
+ - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
144
+ - `0 < α < 1`: Elastic Net
145
+ If a scalar float is provided, that value is used after clipping to [0, 1].
146
+ If a list/iterable of floats is provided, each candidate is evaluated via a full solve, and the α with the smallest NRMSE is selected.
147
+ If None, α is chosen, based on an error rule: α = min(1.0, NRMSE_{α = 0} / (NRMSE_{α = 0} + NRMSE_{α = 1} + tolerance))
145
148
 
146
149
  `*args`, `**kwargs` : optional
147
150
  CVXPY arguments passed to the CVXPY solver.
@@ -1,6 +1,6 @@
1
1
  # Tabular Matrix Problems via Pseudoinverse Estimation
2
2
 
3
- The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net).
3
+ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net). All calculations are performed in numpy.float64 precision.
4
4
 
5
5
  ## Installation
6
6
 
@@ -114,11 +114,14 @@ A symmetric idempotent matrix (projector) defining the subspace for Bott–Duffi
114
114
  `final` : *bool*, default = *True*
115
115
  If *True*, a convex programming problem is solved to refine `zhat`. The resulting solution `z` minimizes a weighted L1/L2 norm around `zhat` subject to `Az = b`.
116
116
 
117
- `alpha` : *float*, default = *1.0*
118
- Regularization parameter (weight) in the final convex program:
119
- - `α = 0`: Lasso (L1 norm)
120
- - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
121
- - `0 < α < 1`: Elastic Net
117
+ `alpha` : *float*, *list[float]* or *None*, default = *None*
118
+ Regularization parameter (weight) in the final convex program:
119
+ - `α = 0`: Lasso (L1 norm)
120
+ - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
121
+ - `0 < α < 1`: Elastic Net
122
+ If a scalar float is provided, that value is used after clipping to [0, 1].
123
+ If a list/iterable of floats is provided, each candidate is evaluated via a full solve, and the α with the smallest NRMSE is selected.
124
+ If None, α is chosen, based on an error rule: α = min(1.0, NRMSE_{α = 0} / (NRMSE_{α = 0} + NRMSE_{α = 1} + tolerance))
122
125
 
123
126
  `*args`, `**kwargs` : optional
124
127
  CVXPY arguments passed to the CVXPY solver.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytmpinv"
3
- version = "1.0.0"
3
+ version = "1.0.1"
4
4
  description = "Tabular Matrix Problems via Pseudoinverse Estimation"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytmpinv
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Tabular Matrix Problems via Pseudoinverse Estimation
5
5
  Author-email: The Economist <29724411+econcz@users.noreply.github.com>
6
6
  License-Expression: MIT
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
 
24
24
  # Tabular Matrix Problems via Pseudoinverse Estimation
25
25
 
26
- The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net).
26
+ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-stage estimation method that reformulates structured table-based systems — such as allocation problems, transaction matrices, and input–output tables — as structured least-squares problems. Based on the [Convex Least Squares Programming (CLSP)](https://pypi.org/project/pyclsp/ "Convex Least Squares Programming") framework, TMPinv solves systems with row and column constraints, block structure, and optionally reduced dimensionality by (1) constructing a canonical constraint form and applying a pseudoinverse-based projection, followed by (2) a convex-programming refinement stage to improve fit, coherence, and regularization (e.g., via Lasso, Ridge, or Elastic Net). All calculations are performed in numpy.float64 precision.
27
27
 
28
28
  ## Installation
29
29
 
@@ -137,11 +137,14 @@ A symmetric idempotent matrix (projector) defining the subspace for Bott–Duffi
137
137
  `final` : *bool*, default = *True*
138
138
  If *True*, a convex programming problem is solved to refine `zhat`. The resulting solution `z` minimizes a weighted L1/L2 norm around `zhat` subject to `Az = b`.
139
139
 
140
- `alpha` : *float*, default = *1.0*
141
- Regularization parameter (weight) in the final convex program:
142
- - `α = 0`: Lasso (L1 norm)
143
- - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
144
- - `0 < α < 1`: Elastic Net
140
+ `alpha` : *float*, *list[float]* or *None*, default = *None*
141
+ Regularization parameter (weight) in the final convex program:
142
+ - `α = 0`: Lasso (L1 norm)
143
+ - `α = 1`: Tikhonov Regularization/Ridge (L2 norm)
144
+ - `0 < α < 1`: Elastic Net
145
+ If a scalar float is provided, that value is used after clipping to [0, 1].
146
+ If a list/iterable of floats is provided, each candidate is evaluated via a full solve, and the α with the smallest NRMSE is selected.
147
+ If None, α is chosen, based on an error rule: α = min(1.0, NRMSE_{α = 0} / (NRMSE_{α = 0} + NRMSE_{α = 1} + tolerance))
145
148
 
146
149
  `*args`, `**kwargs` : optional
147
150
  CVXPY arguments passed to the CVXPY solver.
@@ -1,4 +1,4 @@
1
- __version__ = "1.0.0"
1
+ __version__ = "1.0.1"
2
2
 
3
3
  from .tmpinv import tmpinv
4
4
 
@@ -97,8 +97,8 @@ def TMPinvSolve(
97
97
  The first `m` diagonal entries correspond to row constraints,
98
98
  and the remaining `p` to column constraints.
99
99
  M : array_like of shape (k, m * p), optional
100
- A model matrix with entries in {0, 1}. Each row defines a linear
101
- restriction on the flattened solution matrix. The corresponding
100
+ A model matrix, for example, with entries in {0, 1}. Each row defines a
101
+ linear restriction on the flattened solution matrix. The corresponding
102
102
  right-hand side values must be provided in `b_val`. This block is
103
103
  used to encode known cell values.
104
104
  b_row : array_like of shape (m,)
@@ -144,6 +144,12 @@ def TMPinvSolve(
144
144
  b_col = np.asarray(b_col, dtype=np.float64).reshape(-1, 1)
145
145
  m = b_row.shape[0]
146
146
  p = b_col.shape[0]
147
+ if S is not None:
148
+ S = np.asarray(S, dtype=np.float64)
149
+ if (not np.all((S == -1) | (S == 0) | (S == 1)) or
150
+ np.abs(S).sum(axis=0).max() > 1 or
151
+ np.abs(S).sum(axis=0).max() > 1):
152
+ raise TMPinvInputError("S must be a zero-padded subset of ±I.")
147
153
  if M is not None:
148
154
  M = np.asarray(M, dtype=np.float64)
149
155
  if M.ndim == 1:
@@ -252,7 +258,7 @@ def tmpinv(
252
258
  iteration_limit : int, default = 50
253
259
  Maximum number of iterations allowed in the refinement loop.
254
260
  *args, **kwargs : additional arguments
255
- Passed directly to TMPinvSolver().
261
+ Passed directly to TMPinvSolve().
256
262
 
257
263
  Returns
258
264
  -------
File without changes
File without changes