API abstract classes
Contents
API abstract classes#
BaseSwarm
#
BaseWalkers
#
BaseEnvironment
#
BaseModel
#
BaseTree
#
BaseCritic
#
BaseWrapper
#
Swarm#
Swarm
#
- class fragile.core.swarm.Swarm(n_walkers, env, policy, walkers, callbacks=None, minimize=False, max_epochs=1e+100)[source]#
- Parameters
n_walkers (int) –
policy (fragile.core.api_classes.PolicyAPI) –
walkers (fragile.core.api_classes.WalkersAPI) –
callbacks (Optional[Iterable[fragile.core.api_classes.Callback]]) –
minimize (bool) –
max_epochs (int) –
Walkers#
Walkers
#
- class fragile.core.walkers.Walkers(score=None, diversity=None, minimize=False, score_scale=1.0, diversity_scale=1.0, track_data=None, accumulate_reward=True, keep_max_reward=False, clone_period=1, freeze_walkers=True, **kwargs)[source]#
Walkers class handles the walkers’ dynamics, including scoring, diversity, cloning, and resetting.
Inherits from WalkersAPI.
- Parameters
score (fragile.core.walkers.ScoreMetric) –
diversity (fragile.core.walkers.DiversityMetric) –
minimize (bool) –
score_scale (float) –
diversity_scale (float) –
accumulate_reward (bool) –
keep_max_reward (bool) –
clone_period (int) –
- __init__(score=None, diversity=None, minimize=False, score_scale=1.0, diversity_scale=1.0, track_data=None, accumulate_reward=True, keep_max_reward=False, clone_period=1, freeze_walkers=True, **kwargs)[source]#
Initialize a Walkers object.
- Parameters
score (ScoreMetric, optional) – Scoring metric. Defaults to None.
diversity (DiversityMetric, optional) – Diversity metric. Defaults to None.
minimize (bool, optional) – Whether to minimize the score. Defaults to False.
score_scale (float, optional) – Scaling factor for score. Defaults to 1.0.
diversity_scale (float, optional) – Scaling factor for diversity. Defaults to 1.0.
track_data (iterable, optional) – Data to track. Defaults to None.
accumulate_reward (bool, optional) – Whether to accumulate rewards. Defaults to True.
keep_max_reward (bool, optional) – Whether to keep maximum reward. Defaults to False.
clone_period (int, optional) – Clone period. Defaults to 1.
freeze_walkers (bool, optional) – Whether to freeze walkers. Defaults to True.
**kwargs – Additional keyword arguments.
- balance(inplace=True, **kwargs)[source]#
Balance the walkers.
- Parameters
inplace (bool, optional) – Whether to perform the operation inplace. Defaults to True.
**kwargs – Additional keyword arguments.
- Returns
None if inplace=True, otherwise a StateData object.
- Return type
Union[None, StateData]
- calculate_clones(virtual_rewards, oobs=None)[source]#
Calculate the walkers that will clone and their target companions.
- Parameters
virtual_rewards (array) – Array of walkers’ virtual rewards.
oobs (array, optional) – Array of out-of-bounds flags for walkers. Defaults to None.
- Returns
A dictionary containing clone probabilities, will_clone flags, companion clones, and active flags.
- Return type
- calculate_virtual_reward(scores, diversities, **kwargs)[source]#
Calculate the virtual rewards for walkers based on scores and diversities.
- Parameters
scores (array) – Array of walkers’ scores.
diversities (array) – Array of walkers’ diversities.
**kwargs – Additional keyword arguments.
- Returns
A dictionary containing the virtual rewards.
- Return type
- property inputs: Dict[str, Dict[str, Any]]#
Return a dictionary containing the data that this component needs to function.
- Return type
fragile.core.typing.InputDict
- property outputs: Tuple[str, ...]#
Return a tuple containing the names of the data attribute that the component outputs.
- Return type
Tuple[str, Ellipsis]
- property param_dict: Dict[str, Dict[str, Any]]#
Return the dictionary defining all the data attributes that the component requires.
- Return type
fragile.core.typing.StateDict
- reset(inplace=True, **kwargs)[source]#
Reset the Walkers object and its score and diversity components.
- Parameters
inplace (bool, optional) – Whether to perform the operation inplace. Defaults to True.
**kwargs – Additional keyword arguments.
- Return type
None
- run_epoch(inplace=True, oobs=None, **kwargs)[source]#
Execute an epoch in the walkers’ dynamics.
- Parameters
inplace (bool, optional) – Whether to perform the operation inplace. Defaults to True.
oobs – Out of bounds flags.
**kwargs – Additional keyword arguments.
- Returns
State data after the epoch execution.
- Return type
StateData