吴裕雄--天生自然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 ...
随机推荐
- Django初步皮毛
Django是一个用python编写的Web框架. #Django安装 pip install Django 然后是配置环境变量,将这目录添加到系统环境变量中: C:\Python33\Lib\sit ...
- Linux - Shell - shell 执行方式
概述 shell 的执行方式 背景 偶尔执行个 shell 脚本 一般都用 './script' 执行 最近忽然看到 有不同的执行方式, 感觉有必要整理一下, 然后和大家分享 准备 os centos ...
- Customized Mini LED Keychain For Better Brand Identity
Looking for products that tell people the brand name? Then you'll find an affordable product that wi ...
- LED Decorative Light Manufacturer - LED Neon Rope: 5 Advantages
In the past 100 years, lighting has come a long way. Nowadays, the decorative LED lighting design ca ...
- C语言是菜鸟和大神的分水岭
作为一门古老的编程语言,C语言已经坚挺了好几十年了,初学者从C语言入门,大学将C语言视为基础课程.不管别人如何抨击,如何唱衰,C语言就是屹立不倒:Java.C#.Python.PHP.Perl 等都有 ...
- CentOS6.5-6.9安装 docker
安装docker yum -y install docker-io 备注:查看内核版本uname -r ;卸载docker版本命令 yum remove docker 更改配置文件 vim /etc/ ...
- Android Studio 初级控件笔记
Android支持的像素单位 Android支持的像素单位有:px(像素).in(英寸).mm(毫米).pt(磅,1/72英寸).dp(与设备无关的显示单位).dip(就是dp).sp(用于设置字体大 ...
- 吴裕雄 python 机器学习——集成学习梯度提升决策树GradientBoostingRegressor回归模型
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklear ...
- Python常用数据类型转换
常用的数据类型转换 目标 了解类型转换的作用 掌握常用的类型转换 函数 说明 int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ...
- 在 input 上添加图标字体时无法添加的问题
效果:一个搜索框.如图: 实施过程:一开始,将搜索框分为2部分,用2个 input ,一个 search ,一个 button ,然后给 type="button" 的input ...