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 11"""Implement ensmallen optimizers."""
22
33from dataclasses import dataclass
4+ from typing import Any
45
56import numpy as np
67from numpy .typing import NDArray
@@ -90,11 +91,17 @@ def objective_function(
9091 grad [:] = jac
9192 return np .float64 (fun )
9293
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 )
9498
9599 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" ],
98105 )
99106
100107 return res
You can’t perform that action at this time.
0 commit comments