1 Star 0 Fork 0

丁老板/ZOOpt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
opt.py 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
Yuren Liu 提交于 2020-02-03 23:34 +08:00 . release 0.3
"""
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/boss-ding/ZOOpt.git
git@gitee.com:boss-ding/ZOOpt.git
boss-ding
ZOOpt
ZOOpt
master

搜索帮助