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

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
__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

dict

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

dict

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

setup(swarm)[source]#

Set up the Walkers object by initializing its swarm.

Parameters

swarm – Swarm object to be initialized.

Environment#

Environment (Abstract)#

DiscreteEnv#

Model#

Model (Abstract)#

_DtModel (Abstract)#

ContinuousModel (Abstract)#

DiscreteModel (Abstract)#

DiscreteUniform#

BinarySwap#

ContinuousUniform#

States#

States#

StatesEnv#

StatesModel#

StatesWalkers#

DtSampler#

BaseDtSampler (Abstract)#

ConstantDt#

UniformDt#

GaussianDt#

StateTree#

HistoryTree#

NetworkxTree#

Bounds#

Bounds#