当前位置:网站首页>Pymoo学习 (8):Gradients
Pymoo学习 (8):Gradients
2022-07-25 18:59:00 【因吉】
文章目录
1 Gradients
如果优化问题使用autograd实现,那么可以通过AutomaticDifferentiation来处理:
import autograd.numpy as anp
from pymoo.core.problem import Problem
from pymoo.problems.autodiff import AutomaticDifferentiation
class MyProblem(Problem):
def __init__(self):
super().__init__(n_var=10, n_obj=1, n_constr=0, xl=-5, xu=5)
def _evaluate(self, x, out, *args, **kwargs):
out["F"] = anp.sum(anp.power(x, 2), axis=1)
if __name__ == '__main__':
problem = AutomaticDifferentiation(MyProblem())
X = anp.array([anp.arange(10)])
F, dF = problem.evaluate(X, return_values_of=["F", "dF"])
print(X, F)
print(dF.shape)
print(dF)
输出如下:
[[0 1 2 3 4 5 6 7 8 9]] [[285.]]
(1, 1, 10)
[[[ 0. 2. 4. 6. 8. 10. 12. 14. 16. 18.]]]
参考文献
边栏推荐
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
- Everyone can participate in the official launch of open source activities. We sincerely invite you to experience!
- [translation] LFX 2022 spring tutor qualification opening - apply for CNCF project before February 13!
- MySQL sub query (selected 20 sub query exercises)
- Common file operations
- The understanding of domain adaptation in transfer learning and the introduction of three technologies
- F5:企业数字化转型所需六大能力
- 微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
- 弱网测试工具-QNET
- 浏览器内核有几种,浏览器版本过低怎么升级
猜你喜欢
随机推荐
qt之编译成功但程序无法运行
【加密周报】加密市场有所回温?寒冬仍未解冻!盘点上周加密市场发生的重大事件!
Baklib: make excellent product instruction manual
一个免费的镜像下载仓库网站
Interface automation test platform fasterrunner series (II) - function module
Gan, why ".Length! == 3??
ThreadLocal Kills 11 consecutive questions
Circulaindicator component, which makes the indicator style more diversified
#yyds干货盘点# 面试必刷TOP101:反转链表
PyQt5单击QTableView垂直表头verticalHeader获取行数据以及单击单元格获取行数据操作
房企打响“保交战”
How high are the young people in this class for "ugly things"?
21 days proficient in typescript-4 - type inference and semantic check
蓝牙协议详解(蓝牙是什么)
HTTP cache tongtianpian, there may be something you want
软件测试(思维导图)
【云原生之kubernetes】kubernetes集群下Secret存储对象的管理
浅析IM即时通讯开发出现上网卡顿?网络掉线?
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
Esp32 S3 vscode+idf setup









