Skip to content

Commit 5511c32

Browse files
authored
Move the result analysis snippets to outside of the main example
1 parent e5e8208 commit 5511c32

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

docs/user_guide/general_usage.md

+25-30
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,39 @@ for status_key in searcher.iter_status_keys():
5454
print("===", status_key, "===")
5555
print(searcher.status[status_key])
5656
print()
57+
```
5758

59+
## Extracting and analyzing results
5860

59-
# === Further ways of analyzing the results of the evolutionary run: ===
61+
We now discuss additional ways of analyzing the results of the evolutionary computation. The following code snippets represent possible continuations to the code example above (or to codes similar to it). Therefore, we will continue to refer to the search algorithm as `searcher`.
6062

63+
If the evolutionary algorithm that was used is distribution-based (such as [SNES][evotorch.algorithms.distributed.gaussian.SNES], [XNES][evotorch.algorithms.distributed.gaussian.XNES], [CEM][evotorch.algorithms.distributed.gaussian.CEM], [PGPE][evotorch.algorithms.distributed.gaussian.PGPE], [CMAES][evotorch.algorithms.distributed.cmaes.CMAES]), the status object includes an item with key `"center"`, representing the center (i.e. mean) of the search distribution as a [ReadOnlyTensor][evotorch.tools.readonlytensor.ReadOnlyTensor]:
6164

62-
# If a distribution-based algorithm is used (e.g. SNES, XNES, CEM, PGPE,
63-
# CMAES), the status object includes an item with key "center", representing
64-
# the center (i.e. mean) of the search distribution as a read-only tensor.
65-
#
66-
# center_point_as_tensor = searcher.status["center"]
65+
```python
66+
center_point_as_tensor = searcher.status["center"]
67+
```
6768

69+
Algorithms such as [Cosyne][evotorch.algorithms.ga.Cosyne], [GeneticAlgorithm][evotorch.algorithms.ga.GeneticAlgorithm], etc. do not have a search distribution, therefore, they do not have a center point. However, the best solution of their last population can be obtained via the status key `"pop_best"`, as a [Solution][evotorch.core.Solution] object:
6870

69-
# Algorithms such as Cosyne, GeneticAlgorithm, etc. do not have
70-
# a search distribution, therefore, they do not have a center point.
71-
# However, the best solution of their last population can be obtained
72-
# via the status key "pop_best", as an instance of `evotorch.Solution`.
73-
#
74-
# solution_object = searcher.status["pop_best"]
75-
# decision_values_as_tensor = solution_object.values
76-
# evals_as_tensor = solution_object.evals # fitness(es), evaluation data, etc.
71+
```python
72+
solution_object = searcher.status["pop_best"]
73+
decision_values_as_tensor = solution_object.values
74+
evals_as_tensor = solution_object.evals # fitness(es), evaluation data, etc.
75+
```
7776

77+
If the [Problem][evotorch.core.Problem] object was initialized with `store_solution_stats=True` (which is enabled by default when the device of the Problem is "cpu"), the solution with the best fitness ever observed is available via the status key `"best"`:
7878

79-
# If the Problem object was initialized with `store_solution_stats=True`
80-
# (which is enabled by default when the device of the Problem is "cpu"),
81-
# the solution with the best fitness ever observed is available via the
82-
# status key "best".
83-
#
84-
# best_sln = searcher.status["best"]
85-
# best_sln_decision_values = best_solution.values
86-
# best_sln_evals = best_sln.evals # fitness(s), evaluation data, etc.
79+
```python
80+
best_sln = searcher.status["best"]
81+
best_sln_decision_values = best_solution.values
82+
best_sln_evals = best_sln.evals # fitness(s), evaluation data, etc.
83+
```
8784

85+
Unless the search algorithm was initialized to work across remote actors (via `distributed=True`), the search algorithm keeps its last population accessible via the attribute named `population`.
8886

89-
# Unless the search algorithm was initialized to work across remote
90-
# actors (via `distributed=True`), the search algorithm keeps its last
91-
# population accessible via the attribute named `population`.
92-
#
93-
# for solution in searcher.population:
94-
# print("Decision values:", solution.values)
95-
# print("Evaluation:", solution.evals) # fitnesses, evaluation data, etc.
96-
# print()
87+
```python
88+
for solution in searcher.population:
89+
print("Decision values:", solution.values)
90+
print("Evaluation:", solution.evals) # fitnesses, evaluation data, etc.
91+
print()
9792
```

0 commit comments

Comments
 (0)