pysolvegn.SolveResult#
- class SolveResult(parameters, history, success, stop_code, n_iterations, cost, optimality, term_parameters, elapsed_time, n_rejected, config)[source]#
Result of the optimization performed by
pysolvegn.solve().- Parameters:
parameters (ndarray)
history (List[Dict])
success (bool)
stop_code (int)
n_iterations (int)
cost (float | None)
optimality (float | None)
term_parameters (ndarray | None)
elapsed_time (float)
n_rejected (int)
config (Dict[str, Any])
- parameters#
The optimized input parameters \(\mathbf{p}_{in}\) with shape
(n_parameters,). If no parametrization is provided, these parameters are also the parameters passed directly to the terms. If a parametrization is provided, the corresponding parameters passed to the terms are available interm_parameters.- Type:
numpy.ndarray
- history#
The history of the optimization process. Each element of the list is a dictionary describing one iteration (see the Notes section of
pysolvegn.solve()for the available keys). Empty ifhistoryis False.- Type:
List[Dict]
- success#
True if the optimization stopped because a convergence criterion (
ftol,atol,gtol,xtolorptol) was satisfied. The value is determined with the following priority:Always False if the optimization was stopped by a NaN or Inf value (in the initial parameters, the term parameters, the update or, with
damping="lm", the cost), by a singular linear system, by the callback function, by a failure of the Levenberg-Marquardt step or of the line search, even if a convergence criterion was satisfied at the same iteration.Otherwise True if a convergence criterion was satisfied, even if
max_iterationormax_timewas reached at the same iteration.Otherwise False (stopped by
max_iterationormax_time).
- Type:
bool
- stop_code#
The reasons why the optimization stopped, encoded as a bit mask: one bit per stopping criterion triggered at the last iteration (several criteria can be triggered at the same iteration). Use
stopped_by()to test a criterion, and the propertiesreasonsormessageto get a text description. The bits are listed in the Notes section.- Type:
int
- n_iterations#
The number of iterations performed, i.e. the number of updates \(\Delta\mathbf{p}_{in}^{*}\) applied to the parameters (0 if the optimization stopped at the initial parameters).
- Type:
int
- cost#
The cost function value \(C\) at the returned parameters. If the optimization succeeded (
success=True), the cost is always available (computed at the end if no criterion, damping, callback, history or verbosity required it during the optimization). Otherwise, None if it was not computed or if the terms were not evaluated at the returned parameters (NaN or Inf value in the initial or term parameters).- Type:
Optional[float]
- optimality#
The optimality
norm(g, ord=numpy.inf)at the returned parameters, where \(\mathbf{g}\) is the scaled second term. None if the terms were not evaluated at the returned parameters.- Type:
Optional[float]
- term_parameters#
The parameters passed to the terms, \(\mathbf{p}_{out} = P(\mathbf{p}_{in})\), at the returned parameters (equal to
parametersif no parametrization is provided). None if the optimization did not start (NaN or Inf value inp0).- Type:
Optional[numpy.ndarray]
- elapsed_time#
The total time of the optimization in seconds.
- Type:
float
- n_rejected#
The total number of rejected trial steps of the Levenberg-Marquardt damping or of the line search (0 if
dampingis None andline_searchis False).- Type:
int
- config#
The configuration requested to the solver: the stopping criteria (
"max_iteration","max_time","ftol","xtol","gtol","atol","ptol", None if not used),"damping","lm_conf"(the complete Levenberg-Marquardt configuration, default values included),"line_search"and"line_search_conf"(complete line search configuration).- Type:
Dict[str, Any]
Notes
Bits of
stop_code(stop_codeis the sum of the bits of the criteria triggered at the last iteration):Name
Bit
Meaning
"ftol"1
Relative decrease of the cost <
ftol"atol"2
Cost <
atol"gtol"4
Optimality <
gtol"xtol"8
Relative step <
xtol"ptol"16
Maximal absolute step <
ptol"max_iteration"32
Maximum number of iterations reached
"max_time"64
Maximum computation time reached
"callback"128
Stopped by the callback function
"singular"256
Singular linear system
"lm"512
No acceptable Levenberg-Marquardt step
"naninf_p0"1024
NaN or Inf value in
p0"naninf_term_parameters"2048
NaN or Inf value in \(P(\mathbf{p}_{in})\)
"naninf_cost"4096
NaN or Inf value in the cost (Levenberg-Marquardt)
"naninf_trial_cost"8192
NaN or Inf value in the cost of a trial step
"naninf_update"16384
NaN or Inf value in the update
"line_search"32768
No step satisfying the Armijo condition
"not_descent"65536
Update not a descent direction (line search)
For example,
stop_code = 12 = 4 + 8means thatgtolandxtolwere both satisfied at the last iteration:result.stopped_by("gtol")andresult.stopped_by("xtol")are True.- __init__(parameters, history, success, stop_code, n_iterations, cost, optimality, term_parameters, elapsed_time, n_rejected, config)#
- Parameters:
parameters (ndarray)
history (List[Dict])
success (bool)
stop_code (int)
n_iterations (int)
cost (float | None)
optimality (float | None)
term_parameters (ndarray | None)
elapsed_time (float)
n_rejected (int)
config (Dict[str, Any])
- Return type:
None
Methods
__init__(parameters, history, success, ...)stopped_by(name)Test whether a stopping criterion was triggered at the last iteration.
Attributes
message[Get] A description of the reasons why the optimization stopped (one per line).
reasons[Get] The reasons why the optimization stopped, one string per triggered criterion, each starting with its tag (e.g.
"[xtol] ...").