Skip to content

Commit

Permalink
upd tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
MangaBoba committed Nov 16, 2023
1 parent 23f364a commit 83bf964
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
4 changes: 2 additions & 2 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Tutorials
:glob:
:maxdepth: 1

optimizers
tuners
optimisation
tuning
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
.. role:: raw-html-m2r(raw)
:format: html

Optimizers
==========
Optimisation
============

To solve the optimization problem, 4 optimizers are available in GEFEST - 2 native and 2 based on GOLEM.
Optimisers summary
------------------

To solve the optimisation problem, 4 optimisers are available in GEFEST - 1 native and 2 based on GOLEM.
All of them have a single interface and can be imported from ``gefest.tools.optimizers``.

.. list-table:: Optimizers comparation
:header-rows: 1

* -
- ``BaseGA``
- ``SPEA2``
- ``StandardOptimizer``
- ``SurrogateOptimizer``
* - **Backend**
- GEFEST
- GEFEST
- GOLEM
- GOLEM
* - **Muti objective**
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
* - **Evolutionary schemes**
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
* - **Adaptive mutation strategies**
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`
* - **Surrogate optimization**
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
* - **Surrogate optimisation**
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:green;color:white;font-weight:bold">Yes</code>`

Some details
------------

``BaseGA`` implements the base genetic algorithm, that performs generation of the initial population,
crossover and mutation operations, fitness estimation and selection.
Each of the steps is encapsulated in a separate executor, which allows you to change the logic of individual steps.
Thus, BaseGA essentially only implements the sequence of their call.

``SPEA2`` implements Strength Pareto Evolutionary Algorithm 2 for multiobjective optimization.
Thus, BaseGA essentially only implements the sequence of their call.

``StandardOptimizer`` is a wrapper for GOLEM`s ``EvoGraphOptimizer`` optimizer.
``StandardOptimizer`` is a wrapper for GOLEM`s ``EvoGraphOptimizer`` optimiser.
It allows to select different evolutionary schemes, adaptive mutation strategies and some other features.
To use multiobjective optimization set `golem_selection_type` in ``OptimizationParams`` config to 'spea2'.
To use multiobjective optimisation set `golem_selection_type` in ``OptimizationParams`` config to 'spea2'.

``SurrogateOptimizer`` is the extension of ``StandardOptimizer`` with the ability
to use a surrogate model to evaluate fitness along with the main estimator.

How to run
----------
Selectors summary
-----------------

``OptimizationParams`` have 3 parameters to configure selection strategy:
* ``golem_selection_type`` defines which selection function will be used by GOLEM optimisers. Available values: 'spea2' for multi objective and 'tournament' for single objective problems.
* ``selector`` defines which selection function will be used by GEFEST for single objective problems and also for multi objective fitnesses if it possible. Available values: 'tournament_selection' and 'roulette_selection'.
* ``multiobjective_selector`` defines which selection function will be used by GEFEST for multiobjective problems. Available values: 'spea2' and 'moead'.

Easiest way to run optimizer described in :ref:`quickstart`.
How to optimise
---------------

Easiest way to run optimiser described in :ref:`quickstart`.

If you want to get some more control you can do it in code by import corresponding classes:

.. code-block:: python
from gefest.tools.optimizers BaseGA, SPEA2, StandardOptimizer, SurrogateOptimizer
from gefest.tools.optimizers BaseGA, StandardOptimizer, SurrogateOptimizer
from gefest.core.configs.optimization_params import OptimizationParams
from gefest.core.geometry.datastructs.structure import Structure
Expand All @@ -76,3 +77,6 @@ If you want to get some more control you can do it in code by import correspondi
optimizer = BaseGA(opt_params)
optimized_population = optimizer.optimize(n_steps=42)
By default initial population generates automatically with sampler from `opt_params`.
It also can be provided as optional argument for optimiser constructor.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.. role:: raw-html-m2r(raw)
:format: html

Tuners
Tuning
======

Tuners
------

GEFEST provides api for 4 tuners from `GOLEM <https://thegolem.readthedocs.io/en/latest/api/tuning.html>`_\ :

.. list-table:: Tuners comparation
Expand All @@ -19,7 +22,7 @@ GEFEST provides api for 4 tuners from `GOLEM <https://thegolem.readthedocs.io/en
- simultaneous
- sequential
- simultaneous
* - ****Backend**
* - **Backend**
- `iOpt <https://github.com/aimclub/iOpt>`_
- `Optuna <https://github.com/optuna/optuna>`_
- `Hyperopt <https://github.com/hyperopt/hyperopt>`_
Expand All @@ -30,11 +33,10 @@ GEFEST provides api for 4 tuners from `GOLEM <https://thegolem.readthedocs.io/en
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`
- :raw-html-m2r:`<code style="background:red;color:white;font-weight:bold">No</code>`


How to tune
-----------

To initialize tuner and run tuning, similarly to the optimizers, you need an ``OptimizationParams``
To initialize tuner and run tuning, similarly to the optimisers, you need an ``OptimizationParams``
with defined ``TunerParams`` and also one or more ``Structure`` objects.

More details about ``OptimizationParams`` you can find in `cases` and `API referece` sections of this documentation.
Expand Down
15 changes: 11 additions & 4 deletions gefest/tools/optimizers/golem_optimizer/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import TYPE_CHECKING

from gefest.core.geometry import Structure

if TYPE_CHECKING:
from gefest.core.configs.optimization_params import OptimizationParams

Expand All @@ -23,7 +25,7 @@ class StandardOptimizer(Optimizer):
"""

def __init__(self, opt_params: OptimizationParams, **kwargs) -> None:
def __init__(self, opt_params: OptimizationParams, initial_population=None, **kwargs) -> None:
super().__init__(opt_params.log_dispatcher, **kwargs)
self.opt_params = opt_params
self.objective = Objective(
Expand All @@ -33,9 +35,14 @@ def __init__(self, opt_params: OptimizationParams, **kwargs) -> None:
self.requirements = map_into_graph_requirements(opt_params)
self.ggp = map_into_graph_generation_params(opt_params)
self.gpa = map_into_gpa(opt_params)
self.initial_pop = list(
map(opt_params.golem_adapter.adapt, opt_params.sampler(opt_params.pop_size)),
)

if initial_population:
self.initial_pop = initial_population
else:
self.initial_pop: list[Structure] = list(
map(opt_params.golem_adapter.adapt, opt_params.sampler(opt_params.pop_size)),
)

self.__standard_opt = EvoGraphOptimizer(
objective=self.objective,
initial_graphs=self.initial_pop,
Expand Down
13 changes: 9 additions & 4 deletions gefest/tools/optimizers/golem_optimizer/surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SurrogateOptimizer(Optimizer):
"""

def __init__(self, opt_params: OptimizationParams, **kwargs) -> None:
def __init__(self, opt_params: OptimizationParams, initial_population=None, **kwargs) -> None:
super().__init__(opt_params.log_dispatcher, **kwargs)
self.opt_params = opt_params
self.objective = Objective(
Expand All @@ -35,9 +35,14 @@ def __init__(self, opt_params: OptimizationParams, **kwargs) -> None:
self.requirements = map_into_graph_requirements(opt_params)
self.ggp = map_into_graph_generation_params(opt_params)
self.gpa = map_into_gpa(opt_params)
self.initial_pop = list(
map(opt_params.golem_adapter.adapt, opt_params.sampler(opt_params.pop_size)),
)

if initial_population:
self.initial_pop = initial_population
else:
self.initial_pop: list[Structure] = list(
map(opt_params.golem_adapter.adapt, opt_params.sampler(opt_params.pop_size)),
)

self.__surrogate_opt = SurrogateEachNgenOptimizer(
objective=self.objective,
initial_graphs=self.initial_pop,
Expand Down

0 comments on commit 83bf964

Please sign in to comment.