代码拉取完成,页面将自动刷新
"""
This module contains the class Opt.
Author:
Yu-Ren Liu
"""
from zoopt.algos.opt_algorithms.paretoopt.pareto_optimization import ParetoOptimization
from zoopt.algos.high_dimensionality_handling.sre_optimization import SequentialRandomEmbedding
from zoopt.algos.opt_algorithms.racos.racos_optimization import RacosOptimization
from zoopt.utils.tool_function import ToolFunction
from zoopt.utils.zoo_global import gl
class Opt:
"""
The main entrance of the optimization.
"""
def __init__(self):
return
@staticmethod
def min(objective, parameter):
"""
Minimization function.
:param objective: an Objective object
:param parameter: a Parameter object
:return: the result of the optimization
"""
objective.parameter_set(parameter)
Opt.set_global(parameter)
constraint = objective.get_constraint()
algorithm = parameter.get_algorithm()
if algorithm:
algorithm = algorithm.lower()
result = None
if constraint is not None and ((algorithm is None) or (algorithm == "poss")):
optimizer = ParetoOptimization()
elif constraint is None and ((algorithm is None) or (algorithm == "racos") or (algorithm == "sracos")) or (algorithm == "ssracos"):
optimizer = RacosOptimization()
else:
ToolFunction.log(
"opt.py: No proper algorithm found for %s" % algorithm)
return result
if objective.get_reducedim() is True:
sre = SequentialRandomEmbedding(objective, parameter, optimizer)
result = sre.opt()
else:
result = optimizer.opt(objective, parameter)
result.print_solution()
return result
@staticmethod
def set_global(parameter):
"""
Set global variables.
:param parameter: a Parameter object
:return: no return value
"""
precision = parameter.get_precision()
seed = parameter.get_seed()
if precision:
gl.set_precision(precision)
if seed:
gl.set_seed(seed)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。