evox.core.components#

模块内容#

#

Algorithm

所有算法的基类

Problem

所有问题的基类

Workflow

工作流的基类。

Monitor

监视器基类。

API#

class evox.core.components.Algorithm[源代码]#

Bases: evox.core.module.ModuleBase, abc.ABC

所有算法的基类

Notice

如果子类定义了 steptrace_impl 方法,即使不需要添加任何特殊内容,由于 Python 对象模型的限制,其对应的 init_step 方法必须被覆盖重写。

初始化

初始化 ModuleBase。

参数:
  • *args -- 可变长度参数列表,传递给父类的初始化函数。

  • **kwargs -- 任意关键字参数,传递给父类初始化器。

Attributes: static_names (list): A list to store static member names.

step() None[源代码]#

执行算法过程的一步。

init_step() None[源代码]#

初始化算法并执行算法过程的第一步。

abstract evaluate(pop: torch.Tensor) torch.Tensor[源代码]#

在给定点评估适应度。这个函数是由工作流设置的 Problem.evaluate 的代理函数。默认情况下,这个函数会引发 NotImplementedError

参数:

pop -- 种群。

返回:

适应度。

record_step() None[源代码]#

Record the current step.

class evox.core.components.Problem[源代码]#

Bases: evox.core.module.ModuleBase, abc.ABC

所有问题的基类

初始化

初始化 ModuleBase。

参数:
  • *args -- 可变长度参数列表,传递给父类的初始化函数。

  • **kwargs -- 任意关键字参数,传递给父类初始化器。

Attributes: static_names (list): A list to store static member names.

evaluate(pop: torch.Tensor) torch.Tensor[源代码]#

在给定点评估适应度

参数:

pop -- 种群。

返回:

适应度。

Notice

如果此函数包含无法通过 torch.jit JIT 的外部评估,请使用 torch.jit.ignore 对其进行包装。

class evox.core.components.Workflow(*args, **kwargs)[源代码]#

Bases: evox.core.module.ModuleBase, abc.ABC

工作流的基类。

初始化

初始化 ModuleBase。

参数:
  • *args -- 可变长度参数列表,传递给父类的初始化函数。

  • **kwargs -- 任意关键字参数,传递给父类初始化器。

Attributes: static_names (list): A list to store static member names.

init_step() None[源代码]#

用于让工作流执行一步的函数。

step() None[源代码]#

基本功能以逐步执行工作流。

class evox.core.components.Monitor(*args, **kwargs)[源代码]#

Bases: evox.core.module.ModuleBase, abc.ABC

监视器基类。

监视器用于监控进化过程。它们包含一组回调,这些回调将在工作流执行的特定时刻被调用。Monitor 本身位于主工作流之外,因此不需要 jit。

要实现一个监视器,您需要实现自己的回调并重写 hooks 方法。hooks 方法应返回一个字符串列表,这些字符串是回调的名称。目前支持的回调有:

post_askpre_evalpost_evalpre_tell

初始化

初始化 ModuleBase。

参数:
  • *args -- 可变长度参数列表,传递给父类的初始化函数。

  • **kwargs -- 任意关键字参数,传递给父类初始化器。

Attributes: static_names (list): A list to store static member names.

set_config(**config) evox.core.components.Monitor[源代码]#

根据 config 设置静态变量。

参数:

config -- 配置。

返回:

此模块。

record_auxiliary(aux: Dict[str, torch.Tensor]) None[源代码]#

Record the auxiliary information.

参数:

aux -- The auxiliary information.

post_ask(candidate_solution: torch.Tensor) None[源代码]#

解决方案转换前执行的钩子函数。

参数:

candidate_solution -- 种群(候选解)的初始演化状态

pre_eval(transformed_candidate_solution: Any) None[源代码]#

解决方案转换后执行的钩子函数。

参数:

transformed_candidate_solution -- 经过解的转换后的种群(候选解)。

post_eval(fitness: torch.Tensor) None[源代码]#

在适应度转换之前执行的钩子函数。

参数:

fitness -- 在适应度转换之前的适应度。

pre_tell(transformed_fitness: torch.Tensor) None[源代码]#

在适应度转换后要执行的钩子函数。

参数:

transformed_fitness -- 适应度变换后的适应度值。