Skip to content

Commit e5e8208

Browse files
authored
Update general_usage.md
Extend the general usage docs to mention the status object
1 parent 496e6e2 commit e5e8208

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/user_guide/general_usage.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,58 @@ 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()
57+
58+
59+
# === Further ways of analyzing the results of the evolutionary run: ===
60+
61+
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"]
67+
68+
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.
77+
78+
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.
87+
88+
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()
4597
```

0 commit comments

Comments
 (0)