Free Python optimization framework

Tuesday, July 3, 2007

Automatic gradient check: ready!

here's an example of usage:
let's consider the NLP problem that I published 2 days ago (see here), and let's add the following lines:
p.check.df = 1
p.check.dc = 1
p.check.dh = 1
#also you may add/modify these ones:
prob.diffInt = 1e-07# default value is 1e-7
prob.check.maxViolation = 1e-05 #default value is 1e-5

(diffInt is ised in numerical gradient/subgradient obtaining;
lines where difference between user-supplied and OO-obtained (numerically) gradients are less than prob.check.maxViolation will not be shown)

Run this example and check your output with mine (that is attached in comment to the message)

1 comment:

Dmitrey said...

OpenOpt checks user-supplied gradient df (size: (150,))
according to:
prob.diffInt = 1e-07
prob.check.maxViolation = 1e-05
df num user-supplied numerical difference
21 -1.876e+01 -1.876e+01 -1.030e-05
26 +3.507e-01 +3.507e-01 -1.019e-05
45 -1.595e+00 -1.595e+00 -1.284e-05
46 -1.691e+01 -1.691e+01 -1.008e-05
57 +4.398e+00 +4.398e+00 -1.059e-05
62 +7.761e-01 +7.761e-01 -1.180e-05
67 -1.828e+01 -1.828e+01 -1.721e-05
68 -2.958e+00 -2.958e+00 -1.668e-05
73 -2.178e+01 -2.178e+01 -1.413e-05
74 -7.253e+00 -7.253e+00 -1.169e-05
77 -1.050e+01 -1.050e+01 -1.346e-05
81 +2.427e+00 +2.427e+00 -1.090e-05
88 +5.990e+00 +5.990e+00 -1.414e-05
91 -2.591e+01 -2.591e+01 -1.241e-05
93 -4.921e+00 -4.921e+00 -1.046e-05
104 -2.515e+01 -2.515e+01 -1.317e-05
105 -1.386e+01 -1.386e+01 -1.155e-05
106 +9.838e-01 +9.838e-01 -1.560e-05
119 +4.856e+00 +4.856e+00 -1.461e-05
120 +3.027e+00 +3.027e+00 -1.198e-05
126 +5.104e+00 +5.104e+00 -1.062e-05
127 -6.282e+00 -6.282e+00 -1.066e-05
130 -1.588e+01 -1.588e+01 -1.246e-05
132 +5.977e+00 +5.977e+00 -1.268e-05
133 -2.082e+00 -2.082e+00 -1.101e-05
148 -2.506e+01 -2.506e+01 +1.257e-05
max(abs(df_user - df_numerical)) = 1.72111294887e-05
(is registered in df number 67)
sum(abs(df_user - df_numerical)) = 0.000862997054305
========================
OpenOpt checks user-supplied gradient dc (size: (150, 2))
according to:
prob.diffInt = 1e-07
prob.check.maxViolation = 1e-05
dc num i,j:dc[i]/dx[j] user-supplied numerical difference
0 0 / 0 +4.096e+03 +4.096e+03 -4.787e-05
2 1 / 0 +0.000e+00 -3.638e-05 +3.638e-05
4 2 / 0 +0.000e+00 -3.638e-05 +3.638e-05
6 3 / 0 +0.000e+00 -3.638e-05 +3.638e-05
8 4 / 0 +0.000e+00 -3.638e-05 +3.638e-05
10 5 / 0 +0.000e+00 -3.638e-05 +3.638e-05
12 6 / 0 +0.000e+00 -3.638e-05 +3.638e-05
14 7 / 0 +0.000e+00 -3.638e-05 +3.638e-05
16 8 / 0 +0.000e+00 -3.638e-05 +3.638e-05
18 9 / 0 +0.000e+00 -3.638e-05 +3.638e-05
20 10 / 0 +0.000e+00 -3.638e-05 +3.638e-05
22 11 / 0 +0.000e+00 -3.638e-05 +3.638e-05
24 12 / 0 +0.000e+00 -3.638e-05 +3.638e-05
26 13 / 0 +0.000e+00 -3.638e-05 +3.638e-05
28 14 / 0 +0.000e+00 -3.638e-05 +3.638e-05
30 15 / 0 +0.000e+00 -3.638e-05 +3.638e-05
32 16 / 0 +0.000e+00 -3.638e-05 +3.638e-05
34 17 / 0 +0.000e+00 -3.638e-05 +3.638e-05
36 18 / 0 +0.000e+00 -3.638e-05 +3.638e-05
38 19 / 0 +0.000e+00 -3.638e-05 +3.638e-05
40 20 / 0 +0.000e+00 -3.638e-05 +3.638e-05
42 21 / 0 +0.000e+00 -3.638e-05 +3.638e-05
44 22 / 0 +0.000e+00 -3.638e-05 +3.638e-05
46 23 / 0 +0.000e+00 -3.638e-05 +3.638e-05
48 24 / 0 +0.000e+00 -3.638e-05 +3.638e-05
50 25 / 0 +0.000e+00 -3.638e-05 +3.638e-05
52 26 / 0 +0.000e+00 -3.638e-05 +3.638e-05
54 27 / 0 +0.000e+00 -3.638e-05 +3.638e-05
56 28 / 0 +0.000e+00 -3.638e-05 +3.638e-05
58 29 / 0 +0.000e+00 -3.638e-05 +3.638e-05
60 30 / 0 +0.000e+00 -3.638e-05 +3.638e-05
62 31 / 0 +0.000e+00 -3.638e-05 +3.638e-05
64 32 / 0 +0.000e+00 -3.638e-05 +3.638e-05
66 33 / 0 +0.000e+00 -3.638e-05 +3.638e-05
68 34 / 0 +0.000e+00 -3.638e-05 +3.638e-05
70 35 / 0 +0.000e+00 -3.638e-05 +3.638e-05
72 36 / 0 +0.000e+00 -3.638e-05 +3.638e-05
74 37 / 0 +0.000e+00 -3.638e-05 +3.638e-05
76 38 / 0 +0.000e+00 -3.638e-05 +3.638e-05
78 39 / 0 +0.000e+00 -3.638e-05 +3.638e-05
80 40 / 0 +0.000e+00 -3.638e-05 +3.638e-05
82 41 / 0 +0.000e+00 -3.638e-05 +3.638e-05
84 42 / 0 +0.000e+00 -3.638e-05 +3.638e-05
86 43 / 0 +0.000e+00 -3.638e-05 +3.638e-05
88 44 / 0 +0.000e+00 -3.638e-05 +3.638e-05
90 45 / 0 +0.000e+00 -3.638e-05 +3.638e-05
92 46 / 0 +0.000e+00 -3.638e-05 +3.638e-05
94 47 / 0 +0.000e+00 -3.638e-05 +3.638e-05
96 48 / 0 +0.000e+00 -3.638e-05 +3.638e-05
98 49 / 0 +0.000e+00 -3.638e-05 +3.638e-05
100 50 / 0 +0.000e+00 -3.638e-05 +3.638e-05
102 51 / 0 +0.000e+00 -3.638e-05 +3.638e-05
104 52 / 0 +0.000e+00 -3.638e-05 +3.638e-05
106 53 / 0 +0.000e+00 -3.638e-05 +3.638e-05
108 54 / 0 +0.000e+00 -3.638e-05 +3.638e-05
110 55 / 0 +0.000e+00 -3.638e-05 +3.638e-05
112 56 / 0 +0.000e+00 -3.638e-05 +3.638e-05
114 57 / 0 +0.000e+00 -3.638e-05 +3.638e-05
116 58 / 0 +0.000e+00 -3.638e-05 +3.638e-05
118 59 / 0 +0.000e+00 -3.638e-05 +3.638e-05
120 60 / 0 +0.000e+00 -3.638e-05 +3.638e-05
122 61 / 0 +0.000e+00 -3.638e-05 +3.638e-05
124 62 / 0 +0.000e+00 -3.638e-05 +3.638e-05
126 63 / 0 +0.000e+00 -3.638e-05 +3.638e-05
128 64 / 0 +0.000e+00 -3.638e-05 +3.638e-05
130 65 / 0 +0.000e+00 -3.638e-05 +3.638e-05
132 66 / 0 +0.000e+00 -3.638e-05 +3.638e-05
134 67 / 0 +0.000e+00 -3.638e-05 +3.638e-05
136 68 / 0 +0.000e+00 -3.638e-05 +3.638e-05
138 69 / 0 +0.000e+00 -3.638e-05 +3.638e-05
140 70 / 0 +0.000e+00 -3.638e-05 +3.638e-05
142 71 / 0 +0.000e+00 -3.638e-05 +3.638e-05
144 72 / 0 +0.000e+00 -3.638e-05 +3.638e-05
146 73 / 0 +0.000e+00 -3.638e-05 +3.638e-05
148 74 / 0 +0.000e+00 -3.638e-05 +3.638e-05
150 75 / 0 +0.000e+00 -3.638e-05 +3.638e-05
152 76 / 0 +0.000e+00 -3.638e-05 +3.638e-05
154 77 / 0 +0.000e+00 -3.638e-05 +3.638e-05
156 78 / 0 +0.000e+00 -3.638e-05 +3.638e-05
158 79 / 0 +0.000e+00 -3.638e-05 +3.638e-05
160 80 / 0 +0.000e+00 -3.638e-05 +3.638e-05
162 81 / 0 +0.000e+00 -3.638e-05 +3.638e-05
164 82 / 0 +0.000e+00 -3.638e-05 +3.638e-05
166 83 / 0 +0.000e+00 -3.638e-05 +3.638e-05
168 84 / 0 +0.000e+00 -3.638e-05 +3.638e-05
170 85 / 0 +0.000e+00 -3.638e-05 +3.638e-05
172 86 / 0 +0.000e+00 -3.638e-05 +3.638e-05
174 87 / 0 +0.000e+00 -3.638e-05 +3.638e-05
176 88 / 0 +0.000e+00 -3.638e-05 +3.638e-05
178 89 / 0 +0.000e+00 -3.638e-05 +3.638e-05
180 90 / 0 +0.000e+00 -3.638e-05 +3.638e-05
182 91 / 0 +0.000e+00 -3.638e-05 +3.638e-05
184 92 / 0 +0.000e+00 -3.638e-05 +3.638e-05
186 93 / 0 +0.000e+00 -3.638e-05 +3.638e-05
188 94 / 0 +0.000e+00 -3.638e-05 +3.638e-05
190 95 / 0 +0.000e+00 -3.638e-05 +3.638e-05
192 96 / 0 +0.000e+00 -3.638e-05 +3.638e-05
194 97 / 0 +0.000e+00 -3.638e-05 +3.638e-05
196 98 / 0 +0.000e+00 -3.638e-05 +3.638e-05
198 99 / 0 +0.000e+00 -3.638e-05 +3.638e-05
200 100 / 0 +0.000e+00 -3.638e-05 +3.638e-05
202 101 / 0 +0.000e+00 -3.638e-05 +3.638e-05
204 102 / 0 +0.000e+00 -3.638e-05 +3.638e-05
206 103 / 0 +0.000e+00 -3.638e-05 +3.638e-05
208 104 / 0 +0.000e+00 -3.638e-05 +3.638e-05
210 105 / 0 +0.000e+00 -3.638e-05 +3.638e-05
212 106 / 0 +0.000e+00 -3.638e-05 +3.638e-05
214 107 / 0 +0.000e+00 -3.638e-05 +3.638e-05
216 108 / 0 +0.000e+00 -3.638e-05 +3.638e-05
218 109 / 0 +0.000e+00 -3.638e-05 +3.638e-05
220 110 / 0 +0.000e+00 -3.638e-05 +3.638e-05
222 111 / 0 +0.000e+00 -3.638e-05 +3.638e-05
224 112 / 0 +0.000e+00 -3.638e-05 +3.638e-05
226 113 / 0 +0.000e+00 -3.638e-05 +3.638e-05
228 114 / 0 +0.000e+00 -3.638e-05 +3.638e-05
230 115 / 0 +0.000e+00 -3.638e-05 +3.638e-05
232 116 / 0 +0.000e+00 -3.638e-05 +3.638e-05
234 117 / 0 +0.000e+00 -3.638e-05 +3.638e-05
236 118 / 0 +0.000e+00 -3.638e-05 +3.638e-05
238 119 / 0 +0.000e+00 -3.638e-05 +3.638e-05
240 120 / 0 +0.000e+00 -3.638e-05 +3.638e-05
242 121 / 0 +0.000e+00 -3.638e-05 +3.638e-05
244 122 / 0 +0.000e+00 -3.638e-05 +3.638e-05
246 123 / 0 +0.000e+00 -3.638e-05 +3.638e-05
248 124 / 0 +0.000e+00 -3.638e-05 +3.638e-05
250 125 / 0 +0.000e+00 -3.638e-05 +3.638e-05
252 126 / 0 +0.000e+00 -3.638e-05 +3.638e-05
254 127 / 0 +0.000e+00 -3.638e-05 +3.638e-05
256 128 / 0 +0.000e+00 -3.638e-05 +3.638e-05
258 129 / 0 +0.000e+00 -3.638e-05 +3.638e-05
260 130 / 0 +0.000e+00 -3.638e-05 +3.638e-05
262 131 / 0 +0.000e+00 -3.638e-05 +3.638e-05
264 132 / 0 +0.000e+00 -3.638e-05 +3.638e-05
266 133 / 0 +0.000e+00 -3.638e-05 +3.638e-05
268 134 / 0 +0.000e+00 -3.638e-05 +3.638e-05
270 135 / 0 +0.000e+00 -3.638e-05 +3.638e-05
272 136 / 0 +0.000e+00 -3.638e-05 +3.638e-05
274 137 / 0 +0.000e+00 -3.638e-05 +3.638e-05
276 138 / 0 +0.000e+00 -3.638e-05 +3.638e-05
278 139 / 0 +0.000e+00 -3.638e-05 +3.638e-05
280 140 / 0 +0.000e+00 -3.638e-05 +3.638e-05
282 141 / 0 +0.000e+00 -3.638e-05 +3.638e-05
284 142 / 0 +0.000e+00 -3.638e-05 +3.638e-05
286 143 / 0 +0.000e+00 -3.638e-05 +3.638e-05
288 144 / 0 +0.000e+00 -3.638e-05 +3.638e-05
290 145 / 0 +0.000e+00 -3.638e-05 +3.638e-05
292 146 / 0 +0.000e+00 -3.638e-05 +3.638e-05
294 147 / 0 +0.000e+00 -3.638e-05 +3.638e-05
296 148 / 0 +0.000e+00 -3.638e-05 +3.638e-05
298 149 / 0 +0.000e+00 -3.638e-05 +3.638e-05
max(abs(dc_user - dc_numerical)) = 4.78662564092e-05
(is registered in dc number 0)
sum(abs(dc_user - dc_numerical)) = 0.00546871981781
========================
OpenOpt checks user-supplied gradient dh (size: (150, 2))
according to:
prob.diffInt = 1e-07
prob.check.maxViolation = 1e-05
dh num i,j:dh[i]/dx[j] user-supplied numerical difference
297 148 / 1 -2.944e+03 -2.944e+03 -6.686e-05
298 149 / 0 -8.686e+07 -8.686e+07 -4.414e+00
max(abs(dh_user - dh_numerical)) = 4.41385546327
(is registered in dh number 298)
sum(abs(dh_user - dh_numerical)) = 4.41392232361
========================