import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D def himmeblau(x):
return (x[0]**2 + x[1] - 11)**2 + (x[0] + x[1]**2 - 7)**2 x = np.arange(-6, 6, 0.1)
y = np.arange(-6, 6, 0.1) print(f'x_shape: {x.shape},y_shape: {y.shape}')

# 生成坐标点
X, Y = np.meshgrid(x, y)
print(f'X_shape: {X.shape},Y_shape: {Y.shape}')

Z = himmeblau([X, Y])

fig = plt.figure('himmelblau')
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z)
ax.view_init(60, -30)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()

import tensorflow as tf

x = tf.constant([-4.,0.])

for step in range(200):
with tf.GradientTape() as tape:
tape.watch([x])
y = himmeblau(x)
grads = tape.gradient(y,[x])[0]
x -= 0.01 * grads
if step % 20 == 0:
print(f'step: {step}, x: {x}, f(x): {y}')

最新文章

  1. 常用的shell脚本
  2. MVVM架构~knockoutjs系列之数组的$index和$data
  3. Python数据类型之“文本序列(Text Sequence)”
  4. javascript 创建对象
  5. [推荐]PaaS技术知识贴
  6. json-lib 之jsonConfig具体应用
  7. java_queue
  8. Oracle中Clob类型处理解析:ORA-01461:仅可以插入LONG列的LONG值赋值
  9. C#操作串口总结
  10. C#中Internal class与静态类说明
  11. MongoDB深圳用户组线下活动召集
  12. 谨慎升级到HTTPS
  13. iOS原生和H5的相互调用
  14. JVM的总结
  15. 手把手教您将 libreoffice 移植到函数计算平台
  16. Spark基础-scala学习(五、集合)
  17. 【读书笔记】iOS-对iOS应用进行模糊测试
  18. 关于linux-Centos 7下mysql 5.7.9的rpm包的安装方式
  19. Django框架----用户认证auth模块
  20. 学习笔记37—WIN7系统本地连接没有有效的IP地址 电脑本地连接无有效ip配置怎么办

热门文章

  1. 题解【洛谷P1645/CJOJ1244】序列
  2. Rabbitmq consumer端超时报错
  3. DB技能数据库里把技能伤害调整
  4. Visual Studio 2017:SQLite/SQL Server Compact ToolBox使用
  5. js实现图片轮播图
  6. Django框架-模板层
  7. 概率dp (背包+概率) 背包的多一点
  8. SQL实现group by 分组后组内排序
  9. Codeforces Round #622 (Div. 2)C2
  10. python的datetime库