fragile.core.swarm
Contents
fragile.core.swarm
#
Module Contents#
Classes#
The Swarm implements the iteration logic to make the |
|
It is a swarm adapted to minimize mathematical functions. |
- class fragile.core.swarm.Swarm(n_walkers, env, policy, walkers, callbacks=None, minimize=False, max_epochs=1e+100)[source]#
Bases:
fragile.core.api_classes.SwarmAPI
The Swarm implements the iteration logic to make the
Walkers
evolve.It contains the necessary logic to use an Environment, a Model, and a Walkers instance to create the algorithm execution loop.
This class defines a method called run() that receives two optional arguments, root_walker and state, and has no return value. This method runs the fractal AI Swarm evolution process until a stop condition is met.
In its implementation, it calls several other methods: (before_reset(), reset(), after_reset(), evolve(), before_evolve(), after_evolve(), evolution_end(), before_env(), after_env(), before_policy(), after_policy(), before_walkers(), after_walkers(), run_end()) defined within the same class, which are mainly used to manage different aspects of the search process or to invoke user-defined callbacks.
The evolve() method updates the states of the search environment and model, makes the walkers undergo a perturbation process, and balances them. It also invokes several other methods that trigger user-defined callbacks.
The evolution_end() method returns
True
if any of the following conditions is met: 1. The current epoch exceeds the maximum allowed epochs. 2. All walkers are out of the problem domain. 3. Any callback of the class has set theevolution_end
flag toTrue
.- walkers_last#
If True indicates that the
Walkers
class runs after acting on the environment. If Fase, the walkers run before acting on the environment.- Type
- Parameters
n_walkers (int) – The number of walkers in the swarm.
env (
EnvironmentAPI
) – An environment that simulates the objective function.policy (
PolicyAPI
) – A policy that defines how the individuals evolve.walkers (
WalkersAPI
) – A set of motion rules to control a population of walkers.callbacks (Optional[Iterable[Callback]]) – A list of functions to call at each iteration.
minimize (bool) – If
True
, take the minimum value of fitness, else take the maximum.max_epochs (int) – Maximum number of epochs allowed before the swarm search is stopped.
- class fragile.core.swarm.FunctionMapper(minimize=True, start_same_pos=False, **kwargs)[source]#
Bases:
Swarm
It is a swarm adapted to minimize mathematical functions.
- classmethod from_function(function, bounds, **kwargs)[source]#
Initialize a
FunctionMapper
using a python callable and aBounds
instance.- Parameters
function (Callable) – Callable representing an arbitrary function to be optimized.
bounds (judo.data_structures.bounds.Bounds) – Represents the domain of the function to be optimized.
**kwargs – Passed to
FunctionMapper
__init__.
- Returns
Instance of
FunctionMapper
that optimizes the target function.- Return type
- reset(root_walker=None, state=None)[source]#
Reset the
fragile.Walkers
, theFunction
environment, theModel
and clear the internal data to start a new search process.- Parameters
root_walker (Optional[OneWalker]) – Walker representing the initial state of the search. The walkers will be reset to this walker, and it will be added to the root of the
StateTree
if any.state (Optional[fragile.core.state.SwarmState]) – StateData dictionary that define the initial state of the Swarm.