吴裕雄--天生自然TensorFlow2教程:函数优化实战
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}')
吴裕雄--天生自然TensorFlow2教程:函数优化实战的更多相关文章
- 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...
- 吴裕雄--天生自然TensorFlow2教程:前向传播(张量)- 实战
手写数字识别流程 MNIST手写数字集7000*10张图片 60k张图片训练,10k张图片测试 每张图片是28*28,如果是彩色图片是28*28*3-255表示图片的灰度值,0表示纯白,255表示纯黑 ...
- 吴裕雄--天生自然TensorFlow2教程:反向传播算法
- 吴裕雄--天生自然TensorFlow2教程:链式法则
import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...
- 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...
- 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度
import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...
- 吴裕雄--天生自然TensorFlow2教程:梯度下降简介
import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as ...
随机推荐
- JDK8新特性---stream流
项目上用到了stream流,找篇blog,转载一下,介绍下Stream流的用法. 1 流概述 流是 JDK8 新增的成员,允许以声明性方式处理数据集合,可以把 Stream 流看作是遍历数据集合的一 ...
- 【Python】蟒蛇绘制
来画一只你的小蛇吧! 1. 2. 3.了解turtle库 Turtle,也叫海龟渲染器,使用Turtle库画图也叫海龟作图.Turtle库是Python语言中一个很流行的绘制图像的函数库.海龟渲染器, ...
- mysql忘记密码,更改密码
对MySQL有研究的读者,可能会发现MySQL更新很快,在安装方式上,MySQL提供了两种经典安装方式:解压式和一键式,虽然是两种安装方式,但我更提倡选择解压式安装,不仅快,还干净.在操作系统上,My ...
- 【vue store的使用方法】(this.$store.state this.$store.getters this.$store.dispatch this.$store.commit)
vue 页面文件 <template> <div> {{this.$store.state.count}}<br/> {{count}}<br/> {{ ...
- RNGCryptoServiceProvider 生成订单号
先生成1~1000的随机数 class Program { // Create a new instance of the RNGCryptoServiceProvider. private stat ...
- python eval() 进行条件匹配
最近开发一个功能,根据条件表达式过滤数据,其中用到了eval(条件字符串,字典) 发现一个现象: >>> print u"campGrade in [ '\u51cf\u8 ...
- APP项目下载及运行
1.首先下载Git 2.再下载安装node.js 3.dos窗口下载node.js依赖jar包 执行命令:npm install 4.从Git上down项目 5.运行项目 在项目根目录下 右键 打开 ...
- Docker - Docker Engine 结构结构概述
概述 Docker Engine 结构的简单描述 ref docker 实战 第一本 docker 书 1. docker 版本 1. 版本 Docker Engine - Community 概述 ...
- Spring - 周边设施 - H2 embedded 版本引入
1. 概述 在 Spring 开发中, 引入 H2 做辅助测试数据库 2. 场景 复习 Spring, 复习到 持久化 部分 需要一个 数据库 来做测试 方案 方案1: 搭建 MySQL 实例 虽然现 ...
- JDBC 基础用法学习
JDBC概述 java 数据库链接,sun公司退出的 java 访问数据库的标准规范接口 是一种用于执行SQL语句的 java API 可以作为多种关系数据库提供统一接口 是一组 java 工具类和接 ...