File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 1
1
"""Implement ensmallen optimizers."""
2
2
3
3
from dataclasses import dataclass
4
+ from typing import Any
4
5
5
6
import numpy as np
6
7
from numpy .typing import NDArray
@@ -90,11 +91,17 @@ def objective_function(
90
91
grad [:] = jac
91
92
return np .float64 (fun )
92
93
93
- raw = optimizer .optimize (objective_function , x0 )
94
+ # Passing a Report class to the optimizer allows us to retrieve additional info
95
+ ens_res : dict [str , Any ] = dict ()
96
+ report = pye .Report (resultIn = ens_res , disableOutput = True )
97
+ best_x = optimizer .optimize (objective_function , x0 , report )
94
98
95
99
res = InternalOptimizeResult (
96
- x = raw , # only best x is available
97
- fun = problem .fun (raw ), # best f(x) value is not available
100
+ x = best_x ,
101
+ fun = ens_res ["objective_value" ],
102
+ n_iterations = ens_res ["iterations" ],
103
+ n_fun_evals = ens_res ["evaluate_calls" ],
104
+ n_jac_evals = ens_res ["gradient_calls" ],
98
105
)
99
106
100
107
return res
You can’t perform that action at this time.
0 commit comments