class CMAEvolutionStrategyResult2(object):
Constructor: CMAEvolutionStrategyResult2(xbest, fbest, evals_best, best_feasible, ...)
A results class.
This class is of rather declarative nature allowing to access the result in its attributes after running an optimization. Additionally, the class provides a
namesand anasdictproperty.>>> import cma >>> es = cma.CMA(2 * [1], .1, {'verbose': -9}).optimize(cma.ff.sphere, 4, iterations=5) >>> isinstance(es.result, cma.evolution_strategy.CMAEvolutionStrategyResult2) TrueThe easiest ways to examine the results visually is by list(es.result) or like
>>> es.result.asdict # doctest: +ELLIPSIS {'xbest':...We can also check the available attribute names like
>>> es.result.names # doctest: +ELLIPSIS ['xbest', 'fbest',...and then check a value like
>>> es.result.xbest[0] < 10 TrueOtherwise, the result class acts largely like a
dataclassand like the originalnamedtupleCMAEvolutionStrategyResult, however with _additional_ attributes: as of 2025 the.best_feasibleattribute has been added. For backward compatibility, index access of the original entries is possible but discouraged, like>>> es.result[1] == es.result[-7] == es.result.fbest # deprecated TrueThe nine result attributes are:
xbest best solution evaluated, this may not reflect a good solution under noise or with a changing fitness function like in the constrained case.
fbest objective function value of the best solution
evals_best evaluation count when xbest was evaluated
best_feasible is a dictionary with the keys 'x', 'f', 'evals' (and possibly others), the feasible counterparts to xbest, fbest, evals_best. This is particularly useful with constraints. best_feasible is not accessible by index.
evaluations overall done
iterations overall done
xfavorite final distribution mean in "phenotype" space, considered to be the current best estimate of the optimum.
stds effective final standard deviations, can be used to compute a lower bound on the expected coordinate-wise distance to the true optimum, which is (very!) approximately stds[i] * dim**0.5 * 3 / np.minimum(popsize, 3 * dim + 15) (was: stds[i] * dimension**0.5 / min(mueff, dimension) / 1.5 / 5 ~ stds[i] * dimension**0.5 / min(popsize / 2, dimension) / 5, where dimension = CMAEvolutionStrategy.N and mueff = CMAEvolutionStrategy.sp.weights.mueff ~ 0.3 * popsize).
stop termination conditions in a dictionary.
CAVEAT: in contrast to a named tuple, this class iterates over items, not values, hence dict(es.result) works as expected. list(es.result) is not backward compatible (providing a list of values without keys seems rather pointless given the values are not homogenuous). The previous value of list(es.result) can be obtained by [r[1] for r in es.result].
While not provided in this class, the (penalized-)best solution of the last completed iteration can be accessed via the attribute .pop_sorted[0] of
CMAEvolutionStrategyand the respective objective function value via .fit.fit[0].Details:
- in addition to ._asdict() and dir(.) (which works rather poorly) for the old
CMAEvolutionStrategyResult, viewing with dict(.) and .asdict works for this class too.- list(CMA.fit.idx).index(i) is the index of the i-ths sampled solution of the last completed iteration in pop_sorted. In other words, it is the (original) index of the i+1-th best solution.
Technical details:
- The class allows to have new attributes while keeping backward compatible index access of the original eight attributes of the
namedtupleCMAEvolutionStrategyResult. es.result[-8] still equals es.result[0]. Newly introduced attributes are ignored in this count and cannot be accessed by position index. Index access is discouraged.- inheriting from a
listwould work too, but we would have the list methods as additional attributes.
| Method | __getitem__ |
for backward compatibility, access by the (old) index works too, this is supposed to stay as is forever. |
| Method | __init__ |
set attributes with the arguments resembling namedtuple or dataclass |
| Method | __iter__ |
return iterator over names |
| Method | __len__ |
Undocumented |
| Method | __repr__ |
Undocumented |
| Method | __str__ |
string representation of self. |
| Instance Variable | best |
Undocumented |
| Instance Variable | evals |
Undocumented |
| Instance Variable | evaluations |
Undocumented |
| Instance Variable | fbest |
Undocumented |
| Instance Variable | iterations |
Undocumented |
| Instance Variable | stds |
Undocumented |
| Instance Variable | stop |
Undocumented |
| Instance Variable | xbest |
Undocumented |
| Instance Variable | xfavorite |
Undocumented |
| Property | asdict |
Undocumented |
| Property | names |
list of attribute names |
| Method | _asdict |
Undocumented |
| Instance Variable | _params |
Undocumented |
for backward compatibility, access by the (old) index works too, this is supposed to stay as is forever.
set attributes with the arguments resembling namedtuple or dataclass