pytmpinv 1.2.1__tar.gz → 1.3.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.
- {pytmpinv-1.2.1/pytmpinv.egg-info → pytmpinv-1.3.0}/PKG-INFO +1 -1
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/pyproject.toml +1 -1
- {pytmpinv-1.2.1 → pytmpinv-1.3.0/pytmpinv.egg-info}/PKG-INFO +1 -1
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/tmpinv/__init__.py +1 -1
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/tmpinv/tmpinv.py +25 -15
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/LICENSE +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/README.md +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/pytmpinv.egg-info/SOURCES.txt +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/pytmpinv.egg-info/dependency_links.txt +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/pytmpinv.egg-info/requires.txt +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/pytmpinv.egg-info/top_level.txt +0 -0
- {pytmpinv-1.2.1 → pytmpinv-1.3.0}/setup.cfg +0 -0
|
@@ -77,7 +77,6 @@ def TMPinvSolve(
|
|
|
77
77
|
M: Sequence[Sequence[float]] | None = None,
|
|
78
78
|
b_row: Sequence[float] | None = None,
|
|
79
79
|
b_col: Sequence[float] | None = None,
|
|
80
|
-
b_lim: Sequence[float] | None = None,
|
|
81
80
|
b_val: Sequence[float] | None = None,
|
|
82
81
|
i: int = 1,
|
|
83
82
|
j: int = 1,
|
|
@@ -137,13 +136,13 @@ def TMPinvSolve(
|
|
|
137
136
|
|
|
138
137
|
Notes
|
|
139
138
|
----
|
|
140
|
-
In the reduced model, `S` is ignored. Slack behavior is derived implicitly
|
|
139
|
+
- In the reduced model, `S` is ignored. Slack behavior is derived implicitly
|
|
141
140
|
from block-wise marginal totals. Likewise, `M` must be a unique row subset
|
|
142
141
|
of an identity matrix (i.e., diagonal-only). Arbitrary or non-diagonal model
|
|
143
142
|
matrices cannot be mapped to reduced blocks, making the model infeasible.
|
|
144
|
-
This function
|
|
145
|
-
|
|
146
|
-
reduced model given its replacement of `S`.
|
|
143
|
+
- This function receives internal keyword arguments ['b_lim' : array_like,
|
|
144
|
+
'C_lim' : array_like] from `tmpinv()` containing cell value bounds. These
|
|
145
|
+
arguments are ignored in the reduced model given its replacement of `S`.
|
|
147
146
|
"""
|
|
148
147
|
# (m), (p) Process the parameters, assert conformity, and get dimensions
|
|
149
148
|
if b_row is None or b_col is None:
|
|
@@ -157,9 +156,11 @@ def TMPinvSolve(
|
|
|
157
156
|
m = b_row.shape[0] * i
|
|
158
157
|
p = b_col.shape[0] * j
|
|
159
158
|
if S is not None:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
n_rows = m + p + (kwargs.get("C_lim").shape[0]
|
|
160
|
+
if kwargs.get("C_lim") is not None else 0)
|
|
161
|
+
S = np.asarray(S, dtype=np.float64)
|
|
162
|
+
if S.shape[0] != n_rows:
|
|
163
|
+
raise TMPinvInputError(f"S must have {n_rows} rows.")
|
|
163
164
|
if (not np.all((S == -1) | (S == 0) | (S == 1)) or
|
|
164
165
|
np.abs(S).sum(axis=0).max() > 1 or
|
|
165
166
|
np.abs(S).sum(axis=1).max() > 1):
|
|
@@ -355,8 +356,12 @@ def tmpinv(
|
|
|
355
356
|
-np.hstack([np.zeros((n_cells, S.shape[1] + n_cells)),
|
|
356
357
|
np.eye(n_cells)])])
|
|
357
358
|
finite_rows = np.isfinite(b_lim[:, 0]) # drop rows with ±np.inf
|
|
358
|
-
nonzero_cols = ~np.all(S[
|
|
359
|
-
|
|
359
|
+
nonzero_cols = ~np.all(S[np.concatenate([
|
|
360
|
+
np.ones(S.shape[0] -
|
|
361
|
+
b_lim.shape[0],
|
|
362
|
+
dtype=bool),
|
|
363
|
+
finite_rows]),
|
|
364
|
+
:] == 0, axis=0) # reduce S width
|
|
360
365
|
for _ in range(iteration_limit):
|
|
361
366
|
M_idx, b_val = [], []
|
|
362
367
|
x = result.x.reshape(-1, 1)
|
|
@@ -369,11 +374,16 @@ def tmpinv(
|
|
|
369
374
|
b_val.append(v)
|
|
370
375
|
if len(M_idx) < n_cells:
|
|
371
376
|
M = np.eye(n_cells, dtype=np.float64)[M_idx]
|
|
372
|
-
result = TMPinvSolve(*args,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
+
result = TMPinvSolve(*args, b_lim=(b_lim[finite_rows, :]),
|
|
378
|
+
b_val=b_val,
|
|
379
|
+
C_lim=(C_lim[finite_rows, :]),
|
|
380
|
+
S=(S[np.concatenate([
|
|
381
|
+
np.ones(S.shape[0] -
|
|
382
|
+
b_lim.shape[0],
|
|
383
|
+
dtype=bool),
|
|
384
|
+
finite_rows]),
|
|
385
|
+
:])[:,nonzero_cols],
|
|
386
|
+
M=M, **kw)
|
|
377
387
|
else:
|
|
378
388
|
break
|
|
379
389
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|