Skip to content

Commit dcd66dc

Browse files
authored
Update general_usage.md (#107)
- Extend the general usage docs to mention the status object - Move the result analysis snippets to outside of the main example - Add link to the detailed status item explanations
1 parent 4729c87 commit dcd66dc

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

docs/user_guide/algorithm_usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Each status property can be accessed by its name
4848
best_discovered_solution = searcher.status["best"]
4949
```
5050

51-
All algorithms currently implemented in EvoTorch applied to single-objective problems will *at least* have the following status properties:
51+
Algorithms currently implemented in EvoTorch applied to single-objective problems might have the following status properties:
5252

5353
- `'best'`, the best discovered solution so far.
5454
- `'worst'`, the worst discovered solution so far.

docs/user_guide/general_usage.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@ searcher.run(10)
4040
# Process the information accumulated by the loggers.
4141
...
4242
progress = pandas_logger.to_dataframe()
43-
progress.mean_eval.plot() # Display a graph of the evolutionary progress by using the pandas data frame
43+
progress.mean_eval.plot() # Plot the evolutionary progress
4444
...
45+
46+
# We now analyze the current status using the dictionary-like status object.
47+
# The status object allows one to get evaluation results (i.e. fitness, etc.)
48+
# and decision values of the best solution in the population
49+
# (via the key "pop_best"), center of the search distribution
50+
# (via the key "center", in case a distribution-based evolutionary
51+
# algorithm is being used), etc.
52+
53+
for status_key in searcher.iter_status_keys():
54+
print("===", status_key, "===")
55+
print(searcher.status[status_key])
56+
print()
4557
```
58+
59+
## Extracting and analyzing results
60+
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`.
62+
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]:
64+
65+
```python
66+
center_point_as_tensor = searcher.status["center"]
67+
```
68+
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:
70+
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+
```
76+
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"`:
78+
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+
```
84+
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`.
86+
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()
92+
```
93+
94+
Please see also [here](algorithm_usage.md#accessing-the-status) for details regarding the status items.

0 commit comments

Comments
 (0)