MetaBox
/
  • Quickstart
    • Core Concept
    • Running Logic
    • Installation
    • Common Usage
      • Train
      • Test
    • Config
  • API Reference
    • src
      • src.rl
        • src.rl.utils
        • src.rl.reinforce
        • src.rl.a2c
        • src.rl.qlearning
        • src.rl.basic_agent
        • src.rl.vdn
        • src.rl.ddqn
        • src.rl.ppo
        • src.rl.dqn
      • src.environment
        • src.environment.optimizer
        • src.environment.problem
        • src.environment.parallelenv
        • src.environment.basic_environment
      • src.baseline
        • src.baseline.bbo
        • src.baseline.metabbo
      • src.trainer
      • src.tester
      • src.logger
      • src.config
  • Assets
    • Problem Sets
      • Single-Object Optimization
        • COCO-BBOB
        • BBOB-Surrogate
        • HPO-B
        • Neuroevolution
        • Protein-Docking
        • UAV
        • CEC2013LSGO
      • Multi-Object Optimization
        • MOO-Synthetic
      • Multi-Modal Optimization
        • CEC2013MMO
      • Multi-Task Optimization
        • CEC2017MTO
        • WCCI2020
    • Baselines
  • Developer Guide
    • Develop your MetaBBO
    • Develop your Problem Set
    • Flexible Usage of Metadata
    • Flexibly Integrate other EC Libraries
    • Flexibly Leverage Parallelism

On this page

  • Module Contents
    • Classes
    • API
      • Random_search
        • __str__()
        • __reset()
        • __random_population()
        • run_episode()
MetaEvo/MetaBox 0 0
Edit this page
  1. MetaBox /
  2. API Reference /
  3. src /
  4. src.baseline /
  5. src.baseline.bbo /
  6. src.baseline.bbo.random_search

src.baseline.bbo.random_search¶

Module Contents¶

Classes¶

Random_search

Introduction¶

Random_search is an implementation of a basic random search optimization algorithm, inheriting from Basic_Optimizer. It generates random candidate solutions within the problem bounds and tracks the best solution found so far. The optimizer supports logging of progress and optional collection of full meta-data for analysis.

API¶

class src.baseline.bbo.random_search.Random_search(config)[source]¶

Bases: src.environment.optimizer.basic_optimizer.Basic_Optimizer

Introduction¶

Random_search is an implementation of a basic random search optimization algorithm, inheriting from Basic_Optimizer. It generates random candidate solutions within the problem bounds and tracks the best solution found so far. The optimizer supports logging of progress and optional collection of full meta-data for analysis.

Initialization

Initializes the random search optimizer with the config object constructed in src/config.py.

Args:¶

  • config (object):

    • The Attributes needed for the Random_search in config are the following:

      • maxFEs (int): Maximum number of function evaluations allowed.Defaullt value depends on the type of the problem.

      • n_logpoint (int): Number of log points for tracking progress. Default is 50.

      • log_interval (int): Interval at which logs are recorded.

      • full_meta_data (bool): Flag indicating whether to use full meta data.Default is None.

Attributes:¶

  • __fes (int): Counter for the number of function evaluations performed.Default is 0.

  • log_index (int or None): Index for logging, initialized as None.Default is None.

  • cost (any): Placeholder for cost value, initialized as None.Default is None.

  • __NP (int): Population size, set to 100.

__str__()[source]¶

Returns a string representation of the Random Search optimizer.

Returns:¶

  • str: The name of the optimizer, ‘Random_search’.

__reset(problem)[source]¶

Introduction¶

Resets the internal state of the random search optimizer for a new optimization run on the given problem.

Args:¶

  • problem: The optimization problem instance to initialize the population for.

Effects:¶

  • Resets the function evaluation counter.

  • Clears the cost history.

  • Initializes a new random population.

  • Appends the initial global best solution to the cost history.

  • Sets the log index to 1.

__random_population(problem, init)[source]¶

Introduction¶

Generates a random population of candidate solutions within the problem’s bounds, evaluates their costs, and updates the global best solution.

Args:¶

  • problem (object): The optimization problem instance, expected to have attributes lb (lower bounds), ub (upper bounds), dim (dimension), optimum (optional optimum value), and an eval method for evaluating solutions.

  • init (bool): Indicates whether this is the initial population generation. If True, initializes the global best; otherwise, updates it if a better solution is found.

Side Effects:¶

  • Updates self.meta_Cost and self.meta_X if self.full_meta_data is True.

  • Increments self.__fes by the population size (self.__NP).

  • Updates self.gbest with the minimum cost found in the current population.

run_episode(problem)[source]¶

Introduction¶

Executes a single optimization episode using random search on the provided problem instance. Tracks the best solution found, logs progress at specified intervals, and optionally collects metadata for analysis.

Args:¶

  • problem: An object representing the optimization problem.

Returns:¶

  • dict: A dictionary containing:

    • ‘cost’ (list): The logged best costs at each interval.

    • ‘fes’ (int): The total number of function evaluations performed.

    • ‘metadata’ (dict, optional): If self.full_meta_data is True, includes:

      • ‘X’ (list of np.ndarray): The population positions at each logging interval.

      • ‘Cost’ (list of float): The fitness values of the population at each logging interval.

Notes:¶

  • The function ensures that the cost log is filled up to the required number of log points.

  • If full_meta_data is True, additional metadata about the search process is included in the results.

Previous
src.baseline.bbo.mfea
Next
src.baseline.bbo.jde21

2025, MetaEvo

Made with Sphinx and Shibuya theme.