pytmpinv 1.2.0__tar.gz → 1.2.3__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.2.0/pytmpinv.egg-info → pytmpinv-1.2.3}/PKG-INFO +1 -1
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/pyproject.toml +1 -1
- {pytmpinv-1.2.0 → pytmpinv-1.2.3/pytmpinv.egg-info}/PKG-INFO +1 -1
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/tmpinv/__init__.py +1 -1
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/tmpinv/tmpinv.py +49 -13
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/LICENSE +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/README.md +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/pytmpinv.egg-info/SOURCES.txt +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/pytmpinv.egg-info/dependency_links.txt +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/pytmpinv.egg-info/requires.txt +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/pytmpinv.egg-info/top_level.txt +0 -0
- {pytmpinv-1.2.0 → pytmpinv-1.2.3}/setup.cfg +0 -0
|
@@ -136,10 +136,13 @@ def TMPinvSolve(
|
|
|
136
136
|
|
|
137
137
|
Notes
|
|
138
138
|
----
|
|
139
|
-
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
|
|
140
140
|
from block-wise marginal totals. Likewise, `M` must be a unique row subset
|
|
141
141
|
of an identity matrix (i.e., diagonal-only). Arbitrary or non-diagonal model
|
|
142
142
|
matrices cannot be mapped to reduced blocks, making the model infeasible.
|
|
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`.
|
|
143
146
|
"""
|
|
144
147
|
# (m), (p) Process the parameters, assert conformity, and get dimensions
|
|
145
148
|
if b_row is None or b_col is None:
|
|
@@ -150,12 +153,14 @@ def TMPinvSolve(
|
|
|
150
153
|
raise TMPinvInputError("b_row and b_col must not contain inf or NaN.")
|
|
151
154
|
b_row = np.asarray(b_row, dtype=np.float64).reshape(-1, 1)
|
|
152
155
|
b_col = np.asarray(b_col, dtype=np.float64).reshape(-1, 1)
|
|
153
|
-
m = b_row.shape[0]
|
|
154
|
-
p = b_col.shape[0]
|
|
156
|
+
m = b_row.shape[0] * i
|
|
157
|
+
p = b_col.shape[0] * j
|
|
155
158
|
if S is not None:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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.")
|
|
159
164
|
if (not np.all((S == -1) | (S == 0) | (S == 1)) or
|
|
160
165
|
np.abs(S).sum(axis=0).max() > 1 or
|
|
161
166
|
np.abs(S).sum(axis=1).max() > 1):
|
|
@@ -179,7 +184,8 @@ def TMPinvSolve(
|
|
|
179
184
|
raise TMPinvInputError(f"M and b_val must have the same number "
|
|
180
185
|
f"of rows: "
|
|
181
186
|
f"{M.shape[0]} vs {b_val.shape[0]}")
|
|
182
|
-
kw = {k: v for k, v in kwargs.items() if k not in {"
|
|
187
|
+
kw = {k: v for k, v in kwargs.items() if k not in {"b_lim", "b",
|
|
188
|
+
"C_lim", "S", "M",
|
|
183
189
|
"m", "p",
|
|
184
190
|
"i", "j",
|
|
185
191
|
"zero_diagonal",
|
|
@@ -189,11 +195,15 @@ def TMPinvSolve(
|
|
|
189
195
|
if reduced is None:
|
|
190
196
|
result = TMPinvResult(True, None, np.empty((m, p), dtype=float))
|
|
191
197
|
b_blocks = [b_row, b_col]
|
|
198
|
+
if kwargs.get("b_lim") is not None:
|
|
199
|
+
b_blocks.append(np.asarray(kwargs["b_lim"],
|
|
200
|
+
dtype=np.float64).reshape(-1, 1))
|
|
192
201
|
if b_val is not None:
|
|
193
202
|
b_blocks.append(b_val)
|
|
194
203
|
b = np.vstack(b_blocks)
|
|
195
204
|
result.model = CLSP().solve(*args,
|
|
196
205
|
problem='ap', b=b,
|
|
206
|
+
C=kwargs.get("C_lim"),
|
|
197
207
|
S=S,
|
|
198
208
|
M=M,
|
|
199
209
|
m=m,
|
|
@@ -328,13 +338,30 @@ def tmpinv(
|
|
|
328
338
|
bounds = bounds * n_cells # replicate (low, high)
|
|
329
339
|
if all(l is None and h is None for l, h in bounds):
|
|
330
340
|
return result # finish if unbounded
|
|
331
|
-
if any((l is not None and l < 0) or
|
|
332
|
-
(h is not None and h < 0) for l, h in bounds):
|
|
333
|
-
raise TMPinvInputError("Negative lower or upper bounds are not "
|
|
334
|
-
"allowed in tabular matrix programs.")
|
|
335
|
-
kw = {k: v for k, v in kwargs.items() if k not in {"M", "b_val"}}
|
|
336
341
|
|
|
337
342
|
# (result) Perform bound-constrained iterative refinement
|
|
343
|
+
kw = {k: v for k, v in kwargs.items() if k not in {"b_lim", "b_val",
|
|
344
|
+
"C_lim", "S", "M"}}
|
|
345
|
+
b_lim = np.vstack([np.array([h if h is not None else np.inf for l, h
|
|
346
|
+
in bounds]).reshape(-1, 1),
|
|
347
|
+
np.array([l if l is not None else -np.inf for l, h
|
|
348
|
+
in bounds]).reshape(-1, 1)])
|
|
349
|
+
C_lim = np.vstack([np.tile(np.eye(n_cells), (2,1))])
|
|
350
|
+
S = (kwargs.get("S") if kwargs.get("S") is not None
|
|
351
|
+
else np.zeros((len(kwargs["b_row"]) + len(kwargs["b_col"]), 0)))
|
|
352
|
+
S = np.vstack([np.hstack([S, np.zeros((S.shape[0], 2 * n_cells))]),
|
|
353
|
+
np.hstack([np.zeros((n_cells, S.shape[1])),
|
|
354
|
+
np.eye(n_cells), np.zeros((n_cells,
|
|
355
|
+
n_cells))]),
|
|
356
|
+
-np.hstack([np.zeros((n_cells, S.shape[1] + n_cells)),
|
|
357
|
+
np.eye(n_cells)])])
|
|
358
|
+
finite_rows = np.isfinite(b_lim[:, 0]) # drop rows with ±np.inf
|
|
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
|
|
338
365
|
for _ in range(iteration_limit):
|
|
339
366
|
M_idx, b_val = [], []
|
|
340
367
|
x = result.x.reshape(-1, 1)
|
|
@@ -347,7 +374,16 @@ def tmpinv(
|
|
|
347
374
|
b_val.append(v)
|
|
348
375
|
if len(M_idx) < n_cells:
|
|
349
376
|
M = np.eye(n_cells, dtype=np.float64)[M_idx]
|
|
350
|
-
result = TMPinvSolve(*args,
|
|
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)
|
|
351
387
|
else:
|
|
352
388
|
break
|
|
353
389
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|