1
1
import numpy as np
2
+ from numpy .typing import NDArray
2
3
3
- from optimagic .optimization .history_tools import get_history_arrays
4
+ from optimagic .optimization .history import History
4
5
5
6
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
11
9
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 ]
14
12
15
13
if len (critvals ) < 2 :
16
14
out = None
@@ -35,7 +33,7 @@ def get_convergence_report(history, direction):
35
33
return out
36
34
37
35
38
- def _get_max_f_changes (critvals ) :
36
+ def _get_max_f_changes (critvals : NDArray [ np . float64 ]) -> tuple [ float , float ] :
39
37
best_val = critvals [- 1 ]
40
38
worst_val = critvals [0 ]
41
39
@@ -47,7 +45,7 @@ def _get_max_f_changes(critvals):
47
45
return max_change_rel , max_change_abs
48
46
49
47
50
- def _get_max_x_changes (params ) :
48
+ def _get_max_x_changes (params : NDArray [ np . float64 ]) -> tuple [ float , float ] :
51
49
best_x = params [- 1 ]
52
50
diffs = params - best_x
53
51
denom = np .clip (np .abs (best_x ), 0.1 , np .inf )
0 commit comments