src.environment.optimizer.opro_optimizer

Module Contents

Classes

Functions

scale

Scales the input tensor x to a specified range [lb, ub] using the sigmoid function.

np_scale

Introduction

Scales the input value(s) x to a specified range [lb, ub] using a sigmoid transformation.

API

src.environment.optimizer.opro_optimizer.scale(x, lb, ub)[source]

Scales the input tensor x to a specified range [lb, ub] using the sigmoid function.

Introduction

Applies the sigmoid activation to x, then linearly scales the result to the interval [lb, ub].

Args:

  • x (torch.Tensor): The input tensor to be scaled.

  • lb (float or torch.Tensor): The lower bound of the target range.

  • ub (float or torch.Tensor): The upper bound of the target range.

Returns:

  • torch.Tensor: The scaled tensor with values in the range [lb, ub].

src.environment.optimizer.opro_optimizer.np_scale(x, lb, ub)[source]

Introduction

Scales the input value(s) x to a specified range [lb, ub] using a sigmoid transformation.

Args:

  • x (float or np.ndarray): Input value or array of values to be scaled.

  • lb (float): Lower bound of the target range.

  • ub (float): Upper bound of the target range.

Returns:

  • float or np.ndarray: Scaled value(s) in the range [lb, ub].

Notes:

  • The function first applies the sigmoid function to x, mapping it to (0, 1), and then linearly scales it to the range [lb, ub].

class src.environment.optimizer.opro_optimizer.OPRO_Optimizer(config)[source]

Bases: src.environment.optimizer.learnable_optimizer.Learnable_Optimizer

__str__()[source]

Returns a string representation of the OPRO_Optimizer object.

Returns:

str: The name of the optimizer, "OPRO_Optimizer".
init_population(problem)[source]

Introduction

Initializes the population for the optimization problem, evaluates their fitness, and stores relevant metadata.

Args:

  • problem (object): An optimization problem instance that provides lower and upper bounds (lb, ub), dimensionality (dim), and an evaluation function (func). The problem should also have a reset() method.

Built-in Attribute:

  • self.population (np.ndarray): The initialized population of candidate solutions.

  • self.old_value_pairs (list): List of tuples containing each individual and its corresponding fitness value.

  • self.fes (int): Counter for function evaluations, reset to 0.

  • self.best (float): The best fitness value found in the initial population.

  • self.cost (list): List tracking the best cost found at each step.

  • self.meta_X (list, optional): Stores population snapshots if full_meta_data is enabled in config.

  • self.meta_Cost (list, optional): Stores cost snapshots if full_meta_data is enabled in config.

Returns:

  • list: A list of tuples, each containing a population member and its corresponding fitness value.

Raises:

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

get_old_value_pairs()[source]
update(action, problem)[source]

Introduction

Updates the optimizer’s state with new candidate solutions (thetas) by evaluating them on the given problem, updating the best found solution, and maintaining historical data for meta-learning.

Args:

  • action (list or np.ndarray): A list or array of new candidate solutions (thetas) to evaluate.

  • problem (object): An object representing the optimization problem, which must implement an eval method to evaluate candidate solutions.

Built-in Attribute:

  • self.best (float): The best objective value found so far.

  • self.old_value_pairs (list): List of tuples containing previous thetas and their evaluated values.

  • self.config.full_meta_data (bool): Flag indicating whether to store full meta-data for each generation.

  • self.meta_Cost (list): List of arrays containing costs for meta-learning.

  • self.meta_X (list): List of arrays containing thetas for meta-learning.

  • self.cost (list): List of best costs found at each update.

  • self.fes (int): Counter for the number of function evaluations.

Returns:

  • self.old_value_pairs (list): Updated list of (theta, value) pairs.

  • int: Always 0 (placeholder for compatibility).

  • bool: Always False (placeholder for compatibility).

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

Raises:

  • None explicitly, but may raise exceptions if problem.eval fails or if input shapes are incompatible.