pytmpinv 1.0.0__tar.gz → 1.0.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.
Potentially problematic release.
This version of pytmpinv might be problematic. Click here for more details.
- {pytmpinv-1.0.0/pytmpinv.egg-info → pytmpinv-1.0.2}/PKG-INFO +10 -7
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/README.md +9 -6
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/pyproject.toml +1 -1
- {pytmpinv-1.0.0 → pytmpinv-1.0.2/pytmpinv.egg-info}/PKG-INFO +10 -7
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/tmpinv/__init__.py +1 -1
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/tmpinv/tmpinv.py +13 -7
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/LICENSE +0 -0
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/pytmpinv.egg-info/SOURCES.txt +0 -0
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/pytmpinv.egg-info/dependency_links.txt +0 -0
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/pytmpinv.egg-info/requires.txt +0 -0
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/pytmpinv.egg-info/top_level.txt +0 -0
- {pytmpinv-1.0.0 → pytmpinv-1.0.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytmpinv
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
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 = *
|
|
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 = *
|
|
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
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytmpinv
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
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 = *
|
|
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.
|
|
@@ -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
|
|
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=1).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
|
|
261
|
+
Passed directly to TMPinvSolve().
|
|
256
262
|
|
|
257
263
|
Returns
|
|
258
264
|
-------
|
|
@@ -281,20 +287,20 @@ def tmpinv(
|
|
|
281
287
|
"allowed in tabular matrix programs.")
|
|
282
288
|
|
|
283
289
|
# (result) Perform bound-constrained iterative refinement
|
|
290
|
+
kw = {k: v for k, v in kwargs.items() if k not in {"M", "b_val"}}
|
|
284
291
|
for _ in range(iteration_limit):
|
|
285
292
|
M_idx, b_val = [], []
|
|
286
293
|
x = result.x.reshape(-1, 1)
|
|
287
294
|
for i, (v, (l, h)) in enumerate(zip(x, bounds)):
|
|
295
|
+
v = float(v.item())
|
|
288
296
|
if ((l is not None and v < l - tolerance) or \
|
|
289
297
|
(h is not None and v > h + tolerance)):
|
|
290
298
|
continue # skip out-of-bounds
|
|
291
299
|
M_idx.append(i)
|
|
292
|
-
b_val.append(
|
|
300
|
+
b_val.append(v)
|
|
293
301
|
if len(M_idx) < n_cells:
|
|
294
302
|
M = np.eye(n_cells, dtype=np.float64)[M_idx]
|
|
295
|
-
result = TMPinvSolve(M=M, b_val=b_val,
|
|
296
|
-
*args, **{k: v for k, v in kwargs.items()
|
|
297
|
-
if k not in {"M", "b_val"}})
|
|
303
|
+
result = TMPinvSolve(M=M, b_val=b_val, *args, **kw)
|
|
298
304
|
else:
|
|
299
305
|
break
|
|
300
306
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|