Closed pgkirsch closed 4 years ago
It doesn't even diff for me; looking into it.
fixed in https://github.com/convexengineering/gpkit/pull/1468, where
from gpkit import VectorVariable, Model, Vectorize
import numpy as np
with Vectorize(2):
v = VectorVariable(5, "v", "m")
u = VectorVariable(5, "u", "ft")
m = Model(np.prod(v), [v >= u])
m.substitutions.update({u: np.random.rand(5, 2)})
sol = m.solve(verbosity=0)
with Vectorize(3):
with Vectorize(2):
v = VectorVariable(5, "v", "m")
u = VectorVariable(5, "u", "ft")
m = Model(np.prod(v), [v >= u])
m.substitutions.update({u: np.random.rand(5, 2, 3)})
sol2 = m.solve(verbosity=0)
print("First u")
print(sol.table(tables=["constants"]))
print("Second u")
print(sol2.table(tables=["constants"]))
print(sol.diff(sol2, absdiff=True))
produces
First u
Constants
---------
u : [ 0.878 0.00168 0.341 0.465 0.312 [ft]
0.271 0.75 0.201 0.251 0.356 ]
Second u
Constants
---------
u : [ 0.178 0.531 0.131 0.115 0.363 [ft]
0.129 0.938 0.612 0.835 0.628
0.402 0.143 0.0631 0.854 0.0219
0.0785 0.874 0.353 0.075 0.965
0.237 0.981 0.361 0.162 0.0275
0.902 0.794 0.595 0.213 0.154 ]
Solution difference
(positive means the argument is smaller)
-------------------
u : [ +393.9% -49.0% -98.7% +553.0% -5.9%
+55.4% -50.4% -59.0% -62.6% -43.3%
+118.3% +89.0% -97.3% -12.2% +1460.3%
+155.5% -46.8% -28.9% +315.9% -63.1%
+271.0% -72.4% -99.5% +362.3% +1140.7%
-77.7% -41.5% -57.8% +46.2% +131.0% ]
v : [ +393.9% -49.0% -98.7% +553.0% -5.9%
+55.4% -50.4% -59.0% -62.6% -43.3%
+118.3% +89.0% -97.3% -12.2% +1460.3%
+155.5% -46.8% -28.9% +315.9% -63.1%
+271.0% -72.4% -99.5% +362.3% +1140.7%
-77.7% -41.5% -57.8% +46.2% +131.0% ]
Absolute solution difference
----------------------------
u : [ 0.7 -0.26 -0.13 0.64 -0.021 [ft]
0.071 -0.47 -0.36 -0.52 -0.27
0.48 0.13 -0.061 -0.1 0.32
0.12 -0.41 -0.1 0.24 -0.61
0.64 -0.71 -0.36 0.59 0.31
-0.7 -0.33 -0.34 0.099 0.2 ]
v : [ 0.21 -0.079 -0.039 0.19 -0.0065 [m]
0.022 -0.14 -0.11 -0.16 -0.083
0.14 0.039 -0.019 -0.032 0.097
0.037 -0.12 -0.031 0.072 -0.19
0.2 -0.22 -0.11 0.18 0.096
-0.21 -0.1 -0.1 0.03 0.062 ]
Solution sensitivity delta
--------------------------
The largest sensitivity delta is +0
trying to compare the absolute deltas to the constants tables will show you just how these are broadcast :p
Woop thank you! And +1 for supporting "tiled"(?) comparisons.
Not unrelated to #1465 (which I promise I will reply to soon).
As part of converting a model from
m x n
vectorization tol x m x n
vectorization, I want to baby-step via a1 x m x n
solution and diff.I would expect the diff to be of length
m x n
for each var, instead I seem to be gettingm x m x n
length diffs.MWE (adapted from @1ozturkbe's example, thank you):