src.environment.optimizer.rnnopt_optimizer

Module Contents

Classes

RNNOPT_Optimizer

Introduction

L2L_Optimizer is a learnable optimizer class that manages the optimization process for a given problem, tracking the best solution found and the cost history. It supports both rollout and standard evaluation modes, and terminates after a fixed number of function evaluations or when the optimum is known.

Functions

scale

Introduction

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

np_scale

Introduction

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

API

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

Introduction

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

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.rnnopt_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): The input value or array of values to be scaled.

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

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

Returns:

  • float or np.ndarray: The scaled value(s) within the range [lb, ub].

class src.environment.optimizer.rnnopt_optimizer.RNNOPT_Optimizer(config)[source]

Bases: src.environment.optimizer.learnable_optimizer.Learnable_Optimizer

Introduction

L2L_Optimizer is a learnable optimizer class that manages the optimization process for a given problem, tracking the best solution found and the cost history. It supports both rollout and standard evaluation modes, and terminates after a fixed number of function evaluations or when the optimum is known.

Initialization

Initializes the optimizer with the given configuration.

Args:

  • config (dict): Configuration parameters for the optimizer.

Returns:

  • None

__str__()[source]

Returns a string representation of the RNN optimizer.

Returns:

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

Introduction

Initializes the population and internal state variables for the optimizer.

Args:

  • problem: The optimization problem instance for which the population is to be initialized.

Built-in Attributes:

  • self.__fes (int): Function evaluation counter, initialized to zero.

  • self.cost (list): List to track the cost history, initialized as empty.

  • self.__best (Any): Tracker for the best solution found, initialized to None.

  • self.meta_X (list): List to store the input data for meta-learning, initialized as empty.

  • self.meta_Cost (list): List to store the cost data for meta-learning, initialized as empty.

Effects:

  • Resets the function evaluation counter (__fes) to zero.

  • Initializes the cost list (cost) as empty.

  • Sets the best solution tracker (__best) to None.

update(action, problem)[source]

Introduction

Updates the optimizer state based on the provided action and problem instance. Scales the action, evaluates it on the problem, tracks the best result, and determines if the optimization process is done.

Args:

  • action (Any): The action to be evaluated, can be a numpy array or other type.

  • problem (object): The problem instance, expected to have lb, ub, eval(), and optimum attributes.

Returns:

  • y (float or np.ndarray): The evaluated result (possibly shifted by the optimum).

  • int: Always 0 (placeholder for compatibility).

  • bool: Whether the optimization process is done.

Notes:

  • Updates internal state variables such as the best result found, evaluation count, and cost history.

  • The process is considered done if the optimum is known or if the number of function evaluations reaches 100.