pytmpinv 1.6.0__tar.gz → 2.5.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.
Potentially problematic release.
This version of pytmpinv might be problematic. Click here for more details.
- {pytmpinv-1.6.0/pytmpinv.egg-info → pytmpinv-2.5.0}/PKG-INFO +4 -4
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/README.md +2 -2
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/pyproject.toml +2 -2
- {pytmpinv-1.6.0 → pytmpinv-2.5.0/pytmpinv.egg-info}/PKG-INFO +4 -4
- pytmpinv-2.5.0/pytmpinv.egg-info/requires.txt +2 -0
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/tmpinv/__init__.py +1 -1
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/tmpinv/tmpinv.py +47 -41
- pytmpinv-1.6.0/pytmpinv.egg-info/requires.txt +0 -2
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/LICENSE +0 -0
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/pytmpinv.egg-info/SOURCES.txt +0 -0
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/pytmpinv.egg-info/dependency_links.txt +0 -0
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/pytmpinv.egg-info/top_level.txt +0 -0
- {pytmpinv-1.6.0 → pytmpinv-2.5.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytmpinv
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.5.0
|
|
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
|
|
@@ -18,7 +18,7 @@ Requires-Python: >=3.10
|
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Requires-Dist: numpy>=1.24
|
|
21
|
-
Requires-Dist: pyclsp>=
|
|
21
|
+
Requires-Dist: pyclsp>=3.0.0
|
|
22
22
|
Dynamic: license-file
|
|
23
23
|
|
|
24
24
|
# Tabular Matrix Problems via Pseudoinverse Estimation
|
|
@@ -28,7 +28,7 @@ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-s
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
pip install
|
|
31
|
+
pip install pytmpinv
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Quick Example
|
|
@@ -101,7 +101,7 @@ print(" Diagnostic band (max):", fmt(np.max(result.model.x_upper)))
|
|
|
101
101
|
print(" Bootstrap t-test:")
|
|
102
102
|
for kw, val in result.model.ttest(sample_size=30, # NRMSE sample
|
|
103
103
|
seed=seed, distribution="normal", # seed and distribution
|
|
104
|
-
|
|
104
|
+
).items():
|
|
105
105
|
print(f" {kw}: {float(val):.6f}")
|
|
106
106
|
|
|
107
107
|
# AP (TM), based on a trade matrix, with a zero diagonal and 20% of known values
|
|
@@ -5,7 +5,7 @@ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-s
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pip install
|
|
8
|
+
pip install pytmpinv
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Example
|
|
@@ -78,7 +78,7 @@ print(" Diagnostic band (max):", fmt(np.max(result.model.x_upper)))
|
|
|
78
78
|
print(" Bootstrap t-test:")
|
|
79
79
|
for kw, val in result.model.ttest(sample_size=30, # NRMSE sample
|
|
80
80
|
seed=seed, distribution="normal", # seed and distribution
|
|
81
|
-
|
|
81
|
+
).items():
|
|
82
82
|
print(f" {kw}: {float(val):.6f}")
|
|
83
83
|
|
|
84
84
|
# AP (TM), based on a trade matrix, with a zero diagonal and 20% of known values
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pytmpinv"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.5.0"
|
|
4
4
|
description = "Tabular Matrix Problems via Pseudoinverse Estimation"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -27,7 +27,7 @@ classifiers = [
|
|
|
27
27
|
]
|
|
28
28
|
dependencies = [
|
|
29
29
|
"numpy>=1.24",
|
|
30
|
-
"pyclsp>=
|
|
30
|
+
"pyclsp>=3.0.0"
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
[project.urls]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytmpinv
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.5.0
|
|
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
|
|
@@ -18,7 +18,7 @@ Requires-Python: >=3.10
|
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Requires-Dist: numpy>=1.24
|
|
21
|
-
Requires-Dist: pyclsp>=
|
|
21
|
+
Requires-Dist: pyclsp>=3.0.0
|
|
22
22
|
Dynamic: license-file
|
|
23
23
|
|
|
24
24
|
# Tabular Matrix Problems via Pseudoinverse Estimation
|
|
@@ -28,7 +28,7 @@ The **Tabular Matrix Problems via Pseudoinverse Estimation (TMPinv)** is a two-s
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
pip install
|
|
31
|
+
pip install pytmpinv
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Quick Example
|
|
@@ -101,7 +101,7 @@ print(" Diagnostic band (max):", fmt(np.max(result.model.x_upper)))
|
|
|
101
101
|
print(" Bootstrap t-test:")
|
|
102
102
|
for kw, val in result.model.ttest(sample_size=30, # NRMSE sample
|
|
103
103
|
seed=seed, distribution="normal", # seed and distribution
|
|
104
|
-
|
|
104
|
+
).items():
|
|
105
105
|
print(f" {kw}: {float(val):.6f}")
|
|
106
106
|
|
|
107
107
|
# AP (TM), based on a trade matrix, with a zero diagonal and 20% of known values
|
|
@@ -40,11 +40,11 @@ class TMPinvInputError(Exception):
|
|
|
40
40
|
full_message = f"{message} (Code: {code})" if code is not None \
|
|
41
41
|
else message
|
|
42
42
|
super().__init__(full_message)
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
def __str__(self) -> str:
|
|
45
45
|
return self.message if self.code is None \
|
|
46
46
|
else f"{self.message} [Code: {self.code}]"
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
def as_dict(self) -> dict:
|
|
49
49
|
"""
|
|
50
50
|
Return the error as a dictionary for structured logging or JSON output.
|
|
@@ -168,9 +168,9 @@ def TMPinvSolve(
|
|
|
168
168
|
arguments are ignored in the reduced model given its replacement of `S`.
|
|
169
169
|
"""
|
|
170
170
|
# (m), (p) Process the parameters, assert conformity, and get dimensions
|
|
171
|
-
if
|
|
171
|
+
if b_row is None or b_col is None:
|
|
172
172
|
raise TMPinvInputError("Both b_row and b_col must be provided.")
|
|
173
|
-
if
|
|
173
|
+
if len(b_row) < 2 or len(b_col) < 2:
|
|
174
174
|
raise TMPinvInputError("Minimum length for b_row and b_col is 2.")
|
|
175
175
|
if not np.isfinite(b_row).all() or not np.isfinite(b_col).all():
|
|
176
176
|
raise TMPinvInputError("b_row and b_col must not contain inf or NaN.")
|
|
@@ -297,17 +297,11 @@ def TMPinvSolve(
|
|
|
297
297
|
p_start = col_block * p_subset
|
|
298
298
|
p_end = min(p_start + p_subset, p)
|
|
299
299
|
C_subset = None
|
|
300
|
-
S_subset = np.eye((m_end - m_start) + (p_end - p_start)
|
|
300
|
+
S_subset = np.eye((m_end - m_start) + (p_end - p_start),
|
|
301
|
+
dtype=np.float64)
|
|
301
302
|
b_subset = [b_row[m_start:m_end].reshape(-1, 1),
|
|
302
303
|
b_col[p_start:p_end].reshape(-1, 1)]
|
|
303
304
|
M_subset = None
|
|
304
|
-
if M is not None:
|
|
305
|
-
subset = X_true[m_start:m_end, p_start:p_end].ravel()
|
|
306
|
-
non_empty = ~np.isnan(subset)
|
|
307
|
-
if non_empty.any():
|
|
308
|
-
b_subset.append(subset[non_empty].reshape(-1, 1))
|
|
309
|
-
M_subset = np.eye(subset.size,
|
|
310
|
-
dtype=np.float64)[non_empty,:]
|
|
311
305
|
if kwargs.get("b_lim") is not None:
|
|
312
306
|
subset = np.vstack([
|
|
313
307
|
X_lim[ m_start: m_end, p_start:p_end],
|
|
@@ -332,6 +326,13 @@ def TMPinvSolve(
|
|
|
332
326
|
np.hstack([np.zeros((S.shape[0],
|
|
333
327
|
S_subset.shape[1])),
|
|
334
328
|
S]) ])
|
|
329
|
+
if M is not None:
|
|
330
|
+
subset = X_true[m_start:m_end, p_start:p_end].ravel()
|
|
331
|
+
non_empty = ~np.isnan(subset)
|
|
332
|
+
if non_empty.any():
|
|
333
|
+
b_subset.append(subset[non_empty].reshape(-1, 1))
|
|
334
|
+
M_subset = np.eye(subset.size,
|
|
335
|
+
dtype=np.float64)[non_empty,:]
|
|
335
336
|
tmp = CLSP().solve(*args,
|
|
336
337
|
problem='ap', b=np.vstack(b_subset),
|
|
337
338
|
C=C_subset,
|
|
@@ -389,10 +390,13 @@ def tmpinv(
|
|
|
389
390
|
An object containing the fitted CLSP model(s) and the solution
|
|
390
391
|
matrix `x`.
|
|
391
392
|
"""
|
|
392
|
-
# (n_cells)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
393
|
+
# (n_cells) Get cell count from keyword arguments
|
|
394
|
+
if kwargs.get("b_row") is None or kwargs.get("b_col") is None:
|
|
395
|
+
raise TMPinvInputError("Both b_row and b_col must be provided.")
|
|
396
|
+
if len(kwargs.get("b_row")) < 2 or len(kwargs.get("b_col")) < 2:
|
|
397
|
+
raise TMPinvInputError("Minimum length for b_row and b_col is 2.")
|
|
398
|
+
n_cells = (len(kwargs.get("b_row")) * kwargs.get("i", 1) *
|
|
399
|
+
len(kwargs.get("b_col")) * kwargs.get("j", 1))
|
|
396
400
|
if bounds is None:
|
|
397
401
|
bounds = (None, None)
|
|
398
402
|
if isinstance(bounds, tuple):
|
|
@@ -403,8 +407,6 @@ def tmpinv(
|
|
|
403
407
|
f"match number of variables {n_cells}.")
|
|
404
408
|
elif len(bounds) == 1:
|
|
405
409
|
bounds = bounds * n_cells # replicate (low, high)
|
|
406
|
-
if all(l is None and h is None for l, h in bounds):
|
|
407
|
-
return result # finish if unbounded
|
|
408
410
|
|
|
409
411
|
# (result) Perform bound-constrained iterative refinement
|
|
410
412
|
kw = {k: v for k, v in kwargs.items() if k not in {"b_lim", "b_val",
|
|
@@ -430,30 +432,34 @@ def tmpinv(
|
|
|
430
432
|
finite_rows]),
|
|
431
433
|
:] == 0, axis=0) # reduce S width
|
|
432
434
|
for _ in range(iteration_limit):
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
(
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
S=(S[np.concatenate([
|
|
448
|
-
np.ones(S.shape[0] -
|
|
449
|
-
b_lim.shape[0],
|
|
450
|
-
dtype=bool),
|
|
451
|
-
finite_rows]),
|
|
452
|
-
:])[:,nonzero_cols],
|
|
453
|
-
M=M, tolerance=tolerance,
|
|
454
|
-
iteration_limit=iteration_limit, **kw)
|
|
435
|
+
if _ > 0:
|
|
436
|
+
M_idx, b_val = [], []
|
|
437
|
+
x = result.x.reshape(-1, 1)
|
|
438
|
+
for i, (v, (l, h)) in enumerate(zip(x, bounds)):
|
|
439
|
+
v = float(v.item())
|
|
440
|
+
if ((l is not None and v < l - tolerance) or \
|
|
441
|
+
(h is not None and v > h + tolerance)):
|
|
442
|
+
continue # skip out-of-bounds
|
|
443
|
+
M_idx.append(i)
|
|
444
|
+
b_val.append(v)
|
|
445
|
+
if len(M_idx) < n_cells:
|
|
446
|
+
M = np.eye(n_cells, dtype=np.float64)[M_idx]
|
|
447
|
+
else:
|
|
448
|
+
break
|
|
455
449
|
else:
|
|
456
|
-
|
|
450
|
+
M, b_val = kwargs.get("M"), kwargs.get("b_val")
|
|
451
|
+
|
|
452
|
+
result = TMPinvSolve(*args, b_lim=(b_lim[finite_rows, :]),
|
|
453
|
+
b_val=b_val,
|
|
454
|
+
C_lim=(C_lim[finite_rows, :]),
|
|
455
|
+
S=(S[np.concatenate([
|
|
456
|
+
np.ones(S.shape[0] -
|
|
457
|
+
b_lim.shape[0],
|
|
458
|
+
dtype=bool),
|
|
459
|
+
finite_rows]),
|
|
460
|
+
:])[:,nonzero_cols],
|
|
461
|
+
M=M, tolerance=tolerance,
|
|
462
|
+
iteration_limit=iteration_limit, **kw)
|
|
457
463
|
|
|
458
464
|
# (result) Replace out-of-bound values with `replace_value`
|
|
459
465
|
x = result.x.reshape(-1, 1)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|