11import numpy as np
2+ from numpy .typing import NDArray
23
3- from optimagic .optimization .history_tools import get_history_arrays
4+ from optimagic .optimization .history import History
45
56
6- def get_convergence_report (history , direction ):
7- history_arrs = get_history_arrays (
8- history = history ,
9- direction = direction ,
10- )
7+ def get_convergence_report (history : History ) -> dict [str , dict [str , float ]] | None :
8+ is_accepted = history .is_accepted
119
12- critvals = history_arrs . fun [ history_arrs . is_accepted ]
13- params = history_arrs . params [ history_arrs . is_accepted ]
10+ critvals = np . array ( history . fun , dtype = np . float64 )[ is_accepted ]
11+ params = np . array ( history . flat_params , dtype = np . float64 )[ is_accepted ]
1412
1513 if len (critvals ) < 2 :
1614 out = None
@@ -35,7 +33,7 @@ def get_convergence_report(history, direction):
3533 return out
3634
3735
38- def _get_max_f_changes (critvals ) :
36+ def _get_max_f_changes (critvals : NDArray [ np . float64 ]) -> tuple [ float , float ] :
3937 best_val = critvals [- 1 ]
4038 worst_val = critvals [0 ]
4139
@@ -47,7 +45,7 @@ def _get_max_f_changes(critvals):
4745 return max_change_rel , max_change_abs
4846
4947
50- def _get_max_x_changes (params ) :
48+ def _get_max_x_changes (params : NDArray [ np . float64 ]) -> tuple [ float , float ] :
5149 best_x = params [- 1 ]
5250 diffs = params - best_x
5351 denom = np .clip (np .abs (best_x ), 0.1 , np .inf )
0 commit comments