Skip to content

Commit 8c9b4f3

Browse files
committed
Switch to lbfgsb, ensure that correct version of estimagic is used and fix docs.
1 parent 88d63db commit 8c9b4f3

File tree

5 files changed

+92
-89
lines changed

5 files changed

+92
-89
lines changed

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ requirements:
2525
- pytest
2626
- pytest-xdist
2727
- scipy
28-
- estimagic >=0.0.30
28+
- estimagic =0.0.30
2929
- nlopt

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- numba
1919
- mpmath
2020
- pip
21-
- estimagic>=0.0.30
21+
- estimagic=0.0.30
2222
- nlopt
2323
- pip:
2424
- flake8

promotion/replication/replication_iskhakov_et_al_2016.ipynb

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"\n",
5555
"In the case of MPEC also starting values for the discretized expected value function are necessary and they are set to the zero vector every time: $EV^0_1,...,EV^0_{175}=(0,...,0)$. The subscript of 175 also displays the grid size that Iskhakov et al. choose to discretize the continuous variable of mileage. The starting values of the transition probabilities are frequency based in the paper and we follow this approach in our implementation.\n",
5656
"\n",
57-
"All those ingredients can be found below in the code. Further in our code for the NFXP we specify stopping criteria for the fixed point calculation as well as the tolerance at which we switch from contraction steps to Newton-Kantorovich (N-K) steps. Here, there is a first difference in our implementation of the NFXP as there is no switching back from N-K to contraction steps implemented. Furthermore the switching tolerance is solely an absolute one. For the routine to maximize the likelihood function we rely on the BHHH implementation of estimagic which uses a combination of relative and absolute stopping tolerance which also does not exactly match the original paper. \n",
57+
"All those ingredients can be found below in the code. Further in our code for the NFXP we specify stopping criteria for the fixed point calculation as well as the tolerance at which we switch from contraction steps to Newton-Kantorovich (N-K) steps. Here, there is a first difference in our implementation of the NFXP as there is no switching back from N-K to contraction steps implemented. Furthermore the switching tolerance is solely an absolute one. For the routine to maximize the likelihood function we rely on the scipy L-BFGS-B povided by estimagic which uses a combination of relative and absolute stopping tolerance which also does not exactly match the original paper. Further the authors employ the BHHH algorithm instead of the L-BFGS-B which we will follow as well as soon as the algorithm is available on estimagic.\n",
5858
"\n",
5959
"For MPEC we could not rely on KNITRO as in the paper as it is not freely available. In ruspy it is possible to choose from the library of nlopt or use ipopt for MPEC (please see the References below for links to the respective documentation). For the recreation of the table in Iskhakov et al. we decided to use nlopt here. Again the stopping tolerances cannot exactly be set to those of KNITRO in the paper. Another notable difference is that we only give analytical first order derivatives to nlopt. In the paper, on top of that second order analytical derivatives are provided by using automatic differentiation and also the sparsity patterns of both order derivatives are passed in. Apart from that, though, our setup replicates the paper by using upper and lower bounds as well as a properly recentering the expected value function. \n",
6060
"\n",
@@ -137,7 +137,7 @@
137137
" },\n",
138138
" \"optimizer\": {\n",
139139
" \"approach\": \"NFXP\",\n",
140-
" \"algorithm\": \"estimagic_bhhh\",\n",
140+
" \"algorithm\": \"scipy_L-BFGS-B\",\n",
141141
" # implies that we use analytical first order derivatives as opposed to numerical ones\n",
142142
" \"gradient\": \"Yes\", \n",
143143
" },\n",
@@ -320,18 +320,18 @@
320320
" <th rowspan=\"2\" valign=\"top\">0</th>\n",
321321
" <th rowspan=\"2\" valign=\"top\">0</th>\n",
322322
" <th>NFXP</th>\n",
323-
" <td>15.2276</td>\n",
324-
" <td>3.68877</td>\n",
323+
" <td>15.2277</td>\n",
324+
" <td>3.6888</td>\n",
325325
" <td>0.0913333</td>\n",
326326
" <td>0.4475</td>\n",
327327
" <td>0.446</td>\n",
328328
" <td>0.0146667</td>\n",
329-
" <td>1.67625</td>\n",
329+
" <td>0.62913</td>\n",
330330
" <td>1</td>\n",
331-
" <td>18</td>\n",
332-
" <td>19</td>\n",
333-
" <td>400</td>\n",
334-
" <td>153</td>\n",
331+
" <td>14</td>\n",
332+
" <td>15</td>\n",
333+
" <td>320</td>\n",
334+
" <td>108</td>\n",
335335
" </tr>\n",
336336
" <tr>\n",
337337
" <th>MPEC</th>\n",
@@ -341,7 +341,7 @@
341341
" <td>0.4475</td>\n",
342342
" <td>0.446</td>\n",
343343
" <td>0.0146667</td>\n",
344-
" <td>0.825351</td>\n",
344+
" <td>0.642238</td>\n",
345345
" <td>1</td>\n",
346346
" <td>14</td>\n",
347347
" <td>14</td>\n",
@@ -352,18 +352,18 @@
352352
" <th rowspan=\"2\" valign=\"top\">1</th>\n",
353353
" <th rowspan=\"2\" valign=\"top\">0</th>\n",
354354
" <th>NFXP</th>\n",
355-
" <td>11.9635</td>\n",
356-
" <td>2.49318</td>\n",
355+
" <td>11.9636</td>\n",
356+
" <td>2.49321</td>\n",
357357
" <td>0.091</td>\n",
358358
" <td>0.4535</td>\n",
359359
" <td>0.444833</td>\n",
360360
" <td>0.0106667</td>\n",
361-
" <td>1.0243</td>\n",
361+
" <td>0.746165</td>\n",
362362
" <td>1</td>\n",
363-
" <td>9</td>\n",
364-
" <td>11</td>\n",
365-
" <td>240</td>\n",
366-
" <td>82</td>\n",
363+
" <td>14</td>\n",
364+
" <td>17</td>\n",
365+
" <td>355</td>\n",
366+
" <td>120</td>\n",
367367
" </tr>\n",
368368
" <tr>\n",
369369
" <th>MPEC</th>\n",
@@ -373,7 +373,7 @@
373373
" <td>0.4535</td>\n",
374374
" <td>0.444833</td>\n",
375375
" <td>0.0106667</td>\n",
376-
" <td>0.860147</td>\n",
376+
" <td>0.573166</td>\n",
377377
" <td>1</td>\n",
378378
" <td>13</td>\n",
379379
" <td>13</td>\n",
@@ -385,17 +385,17 @@
385385
" <th>0</th>\n",
386386
" <th>NFXP</th>\n",
387387
" <td>12.2255</td>\n",
388-
" <td>2.35603</td>\n",
388+
" <td>2.35604</td>\n",
389389
" <td>0.0825</td>\n",
390390
" <td>0.460333</td>\n",
391391
" <td>0.444833</td>\n",
392392
" <td>0.0121667</td>\n",
393-
" <td>0.909865</td>\n",
393+
" <td>0.807471</td>\n",
394394
" <td>1</td>\n",
395-
" <td>9</td>\n",
396-
" <td>11</td>\n",
397-
" <td>240</td>\n",
398-
" <td>82</td>\n",
395+
" <td>16</td>\n",
396+
" <td>18</td>\n",
397+
" <td>352</td>\n",
398+
" <td>124</td>\n",
399399
" </tr>\n",
400400
" <tr>\n",
401401
" <th>...</th>\n",
@@ -424,7 +424,7 @@
424424
" <td>0.447</td>\n",
425425
" <td>0.448833</td>\n",
426426
" <td>0.0123333</td>\n",
427-
" <td>0.715148</td>\n",
427+
" <td>0.753175</td>\n",
428428
" <td>1</td>\n",
429429
" <td>13</td>\n",
430430
" <td>13</td>\n",
@@ -435,18 +435,18 @@
435435
" <th rowspan=\"2\" valign=\"top\">98</th>\n",
436436
" <th rowspan=\"2\" valign=\"top\">0</th>\n",
437437
" <th>NFXP</th>\n",
438-
" <td>10.9554</td>\n",
439-
" <td>2.19765</td>\n",
438+
" <td>10.9552</td>\n",
439+
" <td>2.19758</td>\n",
440440
" <td>0.0913333</td>\n",
441441
" <td>0.4465</td>\n",
442442
" <td>0.447333</td>\n",
443443
" <td>0.0145</td>\n",
444-
" <td>1.16698</td>\n",
444+
" <td>0.86645</td>\n",
445445
" <td>1</td>\n",
446-
" <td>10</td>\n",
447-
" <td>12</td>\n",
448-
" <td>260</td>\n",
449-
" <td>83</td>\n",
446+
" <td>14</td>\n",
447+
" <td>17</td>\n",
448+
" <td>357</td>\n",
449+
" <td>112</td>\n",
450450
" </tr>\n",
451451
" <tr>\n",
452452
" <th>MPEC</th>\n",
@@ -456,7 +456,7 @@
456456
" <td>0.4465</td>\n",
457457
" <td>0.447333</td>\n",
458458
" <td>0.0145</td>\n",
459-
" <td>0.661679</td>\n",
459+
" <td>0.684407</td>\n",
460460
" <td>1</td>\n",
461461
" <td>12</td>\n",
462462
" <td>12</td>\n",
@@ -467,18 +467,18 @@
467467
" <th rowspan=\"2\" valign=\"top\">99</th>\n",
468468
" <th rowspan=\"2\" valign=\"top\">0</th>\n",
469469
" <th>NFXP</th>\n",
470-
" <td>11.4836</td>\n",
471-
" <td>2.33456</td>\n",
470+
" <td>11.4834</td>\n",
471+
" <td>2.33454</td>\n",
472472
" <td>0.0941667</td>\n",
473473
" <td>0.4485</td>\n",
474474
" <td>0.444667</td>\n",
475475
" <td>0.0125</td>\n",
476-
" <td>1.12599</td>\n",
476+
" <td>0.861002</td>\n",
477477
" <td>1</td>\n",
478-
" <td>10</td>\n",
479-
" <td>12</td>\n",
480-
" <td>260</td>\n",
481-
" <td>89</td>\n",
478+
" <td>14</td>\n",
479+
" <td>16</td>\n",
480+
" <td>331</td>\n",
481+
" <td>111</td>\n",
482482
" </tr>\n",
483483
" <tr>\n",
484484
" <th>MPEC</th>\n",
@@ -488,7 +488,7 @@
488488
" <td>0.4485</td>\n",
489489
" <td>0.444667</td>\n",
490490
" <td>0.0125</td>\n",
491-
" <td>0.759221</td>\n",
491+
" <td>0.755911</td>\n",
492492
" <td>1</td>\n",
493493
" <td>13</td>\n",
494494
" <td>13</td>\n",
@@ -503,58 +503,58 @@
503503
"text/plain": [
504504
" RC theta_11 theta_30 theta_31 \\\n",
505505
"Discount Factor Run Start Approach \n",
506-
"0.975 0 0 NFXP 15.2276 3.68877 0.0913333 0.4475 \n",
506+
"0.975 0 0 NFXP 15.2277 3.6888 0.0913333 0.4475 \n",
507507
" MPEC 15.2386 3.69232 0.0913333 0.4475 \n",
508-
" 1 0 NFXP 11.9635 2.49318 0.091 0.4535 \n",
508+
" 1 0 NFXP 11.9636 2.49321 0.091 0.4535 \n",
509509
" MPEC 11.9649 2.49367 0.091 0.4535 \n",
510-
" 2 0 NFXP 12.2255 2.35603 0.0825 0.460333 \n",
510+
" 2 0 NFXP 12.2255 2.35604 0.0825 0.460333 \n",
511511
"... ... ... ... ... \n",
512512
" 97 0 MPEC 12.3231 2.66631 0.0918333 0.447 \n",
513-
" 98 0 NFXP 10.9554 2.19765 0.0913333 0.4465 \n",
513+
" 98 0 NFXP 10.9552 2.19758 0.0913333 0.4465 \n",
514514
" MPEC 10.9566 2.19815 0.0913333 0.4465 \n",
515-
" 99 0 NFXP 11.4836 2.33456 0.0941667 0.4485 \n",
515+
" 99 0 NFXP 11.4834 2.33454 0.0941667 0.4485 \n",
516516
" MPEC 11.4843 2.33482 0.0941667 0.4485 \n",
517517
"\n",
518518
" theta_32 theta_33 CPU Time Converged \\\n",
519519
"Discount Factor Run Start Approach \n",
520-
"0.975 0 0 NFXP 0.446 0.0146667 1.67625 1 \n",
521-
" MPEC 0.446 0.0146667 0.825351 1 \n",
522-
" 1 0 NFXP 0.444833 0.0106667 1.0243 1 \n",
523-
" MPEC 0.444833 0.0106667 0.860147 1 \n",
524-
" 2 0 NFXP 0.444833 0.0121667 0.909865 1 \n",
520+
"0.975 0 0 NFXP 0.446 0.0146667 0.62913 1 \n",
521+
" MPEC 0.446 0.0146667 0.642238 1 \n",
522+
" 1 0 NFXP 0.444833 0.0106667 0.746165 1 \n",
523+
" MPEC 0.444833 0.0106667 0.573166 1 \n",
524+
" 2 0 NFXP 0.444833 0.0121667 0.807471 1 \n",
525525
"... ... ... ... ... \n",
526-
" 97 0 MPEC 0.448833 0.0123333 0.715148 1 \n",
527-
" 98 0 NFXP 0.447333 0.0145 1.16698 1 \n",
528-
" MPEC 0.447333 0.0145 0.661679 1 \n",
529-
" 99 0 NFXP 0.444667 0.0125 1.12599 1 \n",
530-
" MPEC 0.444667 0.0125 0.759221 1 \n",
526+
" 97 0 MPEC 0.448833 0.0123333 0.753175 1 \n",
527+
" 98 0 NFXP 0.447333 0.0145 0.86645 1 \n",
528+
" MPEC 0.447333 0.0145 0.684407 1 \n",
529+
" 99 0 NFXP 0.444667 0.0125 0.861002 1 \n",
530+
" MPEC 0.444667 0.0125 0.755911 1 \n",
531531
"\n",
532532
" # of Major Iter. # of Func. Eval. \\\n",
533533
"Discount Factor Run Start Approach \n",
534-
"0.975 0 0 NFXP 18 19 \n",
534+
"0.975 0 0 NFXP 14 15 \n",
535535
" MPEC 14 14 \n",
536-
" 1 0 NFXP 9 11 \n",
536+
" 1 0 NFXP 14 17 \n",
537537
" MPEC 13 13 \n",
538-
" 2 0 NFXP 9 11 \n",
538+
" 2 0 NFXP 16 18 \n",
539539
"... ... ... \n",
540540
" 97 0 MPEC 13 13 \n",
541-
" 98 0 NFXP 10 12 \n",
541+
" 98 0 NFXP 14 17 \n",
542542
" MPEC 12 12 \n",
543-
" 99 0 NFXP 10 12 \n",
543+
" 99 0 NFXP 14 16 \n",
544544
" MPEC 13 13 \n",
545545
"\n",
546546
" # of Bellm. Iter. # of N-K Iter. \n",
547547
"Discount Factor Run Start Approach \n",
548-
"0.975 0 0 NFXP 400 153 \n",
548+
"0.975 0 0 NFXP 320 108 \n",
549549
" MPEC NaN NaN \n",
550-
" 1 0 NFXP 240 82 \n",
550+
" 1 0 NFXP 355 120 \n",
551551
" MPEC NaN NaN \n",
552-
" 2 0 NFXP 240 82 \n",
552+
" 2 0 NFXP 352 124 \n",
553553
"... ... ... \n",
554554
" 97 0 MPEC NaN NaN \n",
555-
" 98 0 NFXP 260 83 \n",
555+
" 98 0 NFXP 357 112 \n",
556556
" MPEC NaN NaN \n",
557-
" 99 0 NFXP 260 89 \n",
557+
" 99 0 NFXP 331 111 \n",
558558
" MPEC NaN NaN \n",
559559
"\n",
560560
"[200 rows x 12 columns]"
@@ -1048,7 +1048,7 @@
10481048
" <tr>\n",
10491049
" <th rowspan=\"2\" valign=\"top\">0.975</th>\n",
10501050
" <th>MPEC</th>\n",
1051-
" <td>0.701</td>\n",
1051+
" <td>0.645</td>\n",
10521052
" <td>100.0</td>\n",
10531053
" <td>12.75</td>\n",
10541054
" <td>12.75</td>\n",
@@ -1057,12 +1057,12 @@
10571057
" </tr>\n",
10581058
" <tr>\n",
10591059
" <th>NFXP</th>\n",
1060-
" <td>1.258</td>\n",
1060+
" <td>0.771</td>\n",
10611061
" <td>100.0</td>\n",
1062-
" <td>11.34</td>\n",
1063-
" <td>13.24</td>\n",
1064-
" <td>283.9</td>\n",
1065-
" <td>98.33</td>\n",
1062+
" <td>13.69</td>\n",
1063+
" <td>15.36</td>\n",
1064+
" <td>321.58</td>\n",
1065+
" <td>105.68</td>\n",
10661066
" </tr>\n",
10671067
" </tbody>\n",
10681068
"</table>\n",
@@ -1071,13 +1071,13 @@
10711071
"text/plain": [
10721072
" CPU Time Converged # of Major Iter. \\\n",
10731073
"Discount Factor Approach \n",
1074-
"0.975 MPEC 0.701 100.0 12.75 \n",
1075-
" NFXP 1.258 100.0 11.34 \n",
1074+
"0.975 MPEC 0.645 100.0 12.75 \n",
1075+
" NFXP 0.771 100.0 13.69 \n",
10761076
"\n",
10771077
" # of Func. Eval. # of Bellm. Iter. # of N-K Iter. \n",
10781078
"Discount Factor Approach \n",
10791079
"0.975 MPEC 12.75 NaN NaN \n",
1080-
" NFXP 13.24 283.9 98.33 "
1080+
" NFXP 15.36 321.58 105.68 "
10811081
]
10821082
},
10831083
"execution_count": 15,

ruspy/estimation/estimation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ def estimate_nfxp(
202202

203203
result_cost_params["x"] = min_result[1]["value"].to_numpy()
204204
result_cost_params["fun"] = min_result[0]["fitness"]
205-
result_cost_params["status"] = min_result[0]["status"]
205+
if min_result[0]["status"] == "success":
206+
result_cost_params["status"] = 1
207+
else:
208+
result_cost_params["status"] = 0
206209
result_cost_params["message"] = min_result[0]["message"]
207210
result_cost_params["jac"] = min_result[0]["jacobian"]
208211
result_cost_params["n_evaluations"] = min_result[0]["n_evaluations"]

ruspy/estimation/mpec.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def mpec_loglike_cost_params(
3131
Parameters
3232
----------
3333
maint_func: func
34-
see :func: `maint_func`
34+
see :ref:`maint_func`
3535
maint_func_dev: func
36-
see :func: `maint_func_dev`
36+
see :ref:`maint_func_dev`
3737
num_states : int
3838
The size of the state space.
3939
num_params : int
@@ -116,10 +116,10 @@ def mpec_constraint(
116116
117117
Parameters
118118
----------
119-
maint_func : func
120-
see :func:`maint_func`
119+
maint_func: func
120+
see :ref:`maint_func`
121121
maint_func_dev: func
122-
see :func: `maint_func_dev`
122+
see :ref:`maint_func_dev`
123123
num_states : int
124124
The size of the state space.
125125
num_params : int
@@ -214,9 +214,9 @@ def mpec_loglike_cost_params_derivative(
214214
Parameters
215215
----------
216216
maint_func: func
217-
see :func: `maint_func`
218-
maint_func_dev : func
219-
see :func: `maint_func_dev`
217+
see :ref:`maint_func`
218+
maint_func_dev: func
219+
see :ref:`maint_func_dev`
220220
num_states : int
221221
The size of the state space.
222222
num_params : int
@@ -285,9 +285,9 @@ def mpec_constraint_derivative(
285285
Parameters
286286
----------
287287
maint_func: func
288-
see :func: `maint_func`
289-
maint_func_dev : func
290-
see :func: `maint_func_dev`
288+
see :ref:`maint_func`
289+
maint_func_dev: func
290+
see :ref:`maint_func_dev`
291291
num_states : int
292292
The size of the state space.
293293
num_params : int

0 commit comments

Comments
 (0)