src.environment.optimizer.surrrlde_optimizer

Module Contents

Classes

SurrRLDE_Optimizer

Introduction

SurrRLDE is a novel MetaBBO framework which combines surrogate learning process and reinforcement learning-aided Differential Evolution (DE) algorithm.

API

class src.environment.optimizer.surrrlde_optimizer.SurrRLDE_Optimizer(config)[source]

Bases: src.environment.optimizer.learnable_optimizer.Learnable_Optimizer

Introduction

SurrRLDE is a novel MetaBBO framework which combines surrogate learning process and reinforcement learning-aided Differential Evolution (DE) algorithm.

Original paper

Surrogate Learning in Meta-Black-Box Optimization: A Preliminary Study.” arXiv preprint arXiv:2503.18060 (2025).

Official Implementation

SurrRLDE

Initialization

Introduction

Initializes the optimizer with the given configuration, setting up algorithm parameters, population attributes, and logging controls.

Args:

  • config (object): Configuration object.

    • The Attributes needed for the surrrlde optimizer: - device (str): The device to be used for computation (e.g., ‘cpu’, ‘cuda’). - maxFEs (int): The maximum number of function evaluations. - upperbound (float): The upper bound for the optimization problem. - log_interval (int): The interval for logging progress. - n_logpoint (int): The number of log points. - full_meta_data (bool): Flag to indicate whether to store full meta data.

Built-in Attribute:

  • self.F (float): The mutation factor for DE.Default is 0.5.

  • self.Cr (float): The crossover probability for DE. Default is 0.7.

  • self.pop_size (int): The size of the population. Default is 100.

  • self.maxFEs (int): The maximum number of function evaluations.

  • self.ub (float): The upper bound for the optimization problem.

  • self.lb (float): The lower bound for the optimization problem.

  • self.population (torch.Tensor): The current population of solutions.

  • self.fitness (torch.Tensor): The fitness values of the current population.

  • self.pop_cur_best (torch.Tensor): The best solution in the current population.

  • self.fit_cur_best (torch.Tensor): The fitness value of the best solution in the current population.

  • self.pop_history_best (torch.Tensor): The best solution found so far.Default is None.

  • self.fit_history_best (torch.Tensor): The fitness value of the best solution found so far.Default is None.

  • self.fit_init_best (torch.Tensor): The initial best fitness value.Default is None.

  • self.improved_gen (int): The number of generations since the last improvement.Default is 0.

  • self.fes (int): The number of function evaluations used.Default is None.

  • self.cost (list): The cost history of the best solution found so far.Default is None.

  • self.cur_logpoint (int): The current log point.Default is None.

Returns:

  • None

__str__()[source]

Returns a string representation of the SurrRLDE_Optimizer instance.

Returns:

  • str: The name of the optimizer, “SurrRLDE_Optimizer”.

get_state(problem)[source]

Introduction

Computes a 9-dimensional state vector representing various statistics and progress indicators of the optimizer’s current population and fitness landscape.

Args:

  • problem: The optimization problem instance (not directly used in this method, but may be required for interface compatibility).

Returns:

  • torch.Tensor: A 1D tensor of length 9 containing the following state features: 1. Mean pairwise Euclidean distance between individuals in the population. 2. Mean Euclidean distance between each individual and the current best individual. 3. Mean Euclidean distance between each individual and the historical best individual. 4. Mean Euclidean distance between current fitness values and historical best fitness values. 5. Mean Euclidean distance between current fitness values and current best fitness value. 6. Standard deviation of the current fitness values. 7. Normalized remaining function evaluations: (maxFEs - fes) / maxFEs. 8. Number of generations since last improvement in best fitness. 9. Binary indicator (1 if current best fitness improved over historical best, else 0).

Built-in Attribute:

  • Uses internal attributes such as self.population, self.fitness, self.pop_cur_best, self.pop_history_best, self.fit_cur_best, self.fit_history_best, self.maxFEs, self.fes, and self.improved_gen.

Raises:

  • None explicitly, but assumes all internal attributes are properly initialized and shaped.

init_population(problem)[source]

Introduction

Initializes the population for the optimizer based on the provided problem definition, evaluates the initial fitness, and sets up tracking for the best solutions and meta-data.

Args:

  • problem (object): The optimization problem object which has attributes dim, ub, lb, and methods eval().

Built-in Attribute:

  • self.dim (int): Dimensionality of the problem.

  • self.rng_torch (torch.Generator): Random number generator for torch, set according to device.

  • self.population (torch.Tensor): The initialized population of candidate solutions.

  • self.fitness (torch.Tensor): Fitness values of the population.

  • self.pop_cur_best (torch.Tensor): Current best solution in the population.

  • self.pop_history_best (torch.Tensor): Historical best solution found.

  • self.fit_init_best (torch.Tensor): Initial best fitness value.

  • self.fit_cur_best (torch.Tensor): Current best fitness value.

  • self.fit_history_best (torch.Tensor): Historical best fitness value.

  • self.fes (int): Number of function evaluations performed.

  • self.cost (list): List of best cost values per generation.

  • self.cur_logpoint (int): Current logpoint for logging.

  • self.meta_X (list, optional): Meta-data of populations if full_meta_data is enabled.

  • self.meta_Cost (list, optional): Meta-data of costs if full_meta_data is enabled.

Returns:

  • state (Any): The current state of the optimizer, as returned by self.get_state(problem).

Raises:

  • AttributeError: If the problem object does not have required attributes or methods.

  • TypeError: If the fitness evaluation returns an unexpected type.

update(action, problem)[source]

Introduction

Updates the optimizer’s state based on the selected action and the given problem instance. This includes mutation and crossover operations, fitness evaluation, population update, reward calculation, logging, and meta-data collection.

Args:

  • action (int): An integer representing the chosen mutation strategy and scaling factor (F).

  • problem (object): The problem instance to be optimized. Must provide an eval method and may have an optimum attribute.

Returns:

  • next_state (Any): The next state representation after the update, as returned by get_state(problem).

  • reward (float): The reward signal computed based on improvement in best fitness.

  • is_done (bool): Whether the optimization process has reached its maximum number of function evaluations.

  • info (dict): Additional information (currently empty).

Raises:

  • ValueError: If the provided action is not in the valid range (0-14).

mutation(mut_way)[source]

Introduction

Applies various Differential Evolution (DE) mutation strategies to the current population and returns the mutated population.

Args:

  • mut_way (str): The mutation strategy to use. Supported values are: - ‘DE/rand/1’ - ‘DE/best/1’ - ‘DE/current-to-rand’ - ‘DE/current-to-pbest’ - ‘DE/current-to-best’

Built-in Attribute:

  • self.population (torch.Tensor): The current population of candidate solutions.

  • self.pop_size (int): The number of individuals in the population.

  • self.F (float): The mutation scaling factor.

  • self.lb (float or torch.Tensor): The lower bound(s) for the variables.

  • self.ub (float or torch.Tensor): The upper bound(s) for the variables.

  • self.pop_cur_best (torch.Tensor): The current best individual in the population.

  • self.fitness (torch.Tensor): The fitness values of the population.

  • self.device (torch.device): The device on which tensors are allocated.

  • self.rng_torch (torch.Generator): The random number generator for torch operations.

Returns:

  • torch.Tensor: The mutated population tensor, with the same shape as self.population.

Raises:

  • ValueError: If mut_way is not one of the supported mutation strategies.

crossover(mut_population)[source]

Introduction

Performs the crossover operation in a differential evolution algorithm, combining the current population with a mutated population to generate a new candidate population.

Args:

  • mut_population (torch.Tensor): The mutated population tensor with the same shape as the current population.

Built-in Attribute:

  • self.population (torch.Tensor): The current population tensor.

  • self.pop_size (int): The number of individuals in the population.

  • self.dim (int): The dimensionality of each individual.

  • self.Cr (float): The crossover probability.

  • self.rng_torch (torch.Generator): The random number generator for reproducibility.

  • self.device (torch.device): The device on which tensors are allocated.

Returns:

  • torch.Tensor: The new population tensor after crossover, with the same shape as the input population.

Raises:

  • None

generate_random_int(NP: int, cols: int) torch.Tensor[source]

Introduction

Generates a random integer tensor of shape (NP, cols) where each row contains unique indices not equal to the row index, suitable for population-based optimization algorithms.

Args:

  • NP (int): The population size, determines the number of rows in the output tensor.

  • cols (int): The number of columns in the output tensor, typically the number of unique indices required per row.

Returns:

  • torch.Tensor: A tensor of shape (NP, cols) containing random integers in the range [0, NP), with the constraint that no row contains its own index.

Raises:

  • None