Tensorflow - Implement for generating some 3-dimensional phony data and fitting them with a plane.
Coding according to TensorFlow 官方文档中文版
import tensorflow as tf
import numpy as np ''' Intro. for this python file.
Objective:
Implement for generating some 3-dimensional phony data and fitting them with a plane.
Operating Environment:
python = 3.6.4
tensorflow = 1.5.0
numpy = 1.15.1
''' # Generate phony data using NumPy. There is totally 100 points.
''' numpy.random.rand(d0, d1, ..., dn)
Explanation:
Random values in a given shape.
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
'''
''' numpy.dot(a, b, out=None)
Explanation:
Dot product of two arrays.
'''
x_data = np.float32(np.random.rand(2, 100))
y_data = np.dot([0.100, 0.200], x_data) + 0.300 # Generate a linear model.
''' tf.random_uniform(shape, minval=0, maxval=None, dtype=tf.float32, seed=None, name=None)
Explanation:
shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
minval: A 0-D Tensor or Python value of type dtype. The lower bound on the range of random values to generate.
Defaults to 0.
maxval: A 0-D Tensor or Python value of type dtype. The upper bound on the range of random values to generate.
Defaults to 1 if dtype is floating point.
dtype: The type of the output: float16, float32, float64, int32, or int64.
seed: A Python integer. Used to create a random seed for the distribution. See tf.set_random_seed for behavior.
name: A name for the operation (optional).
'''
''' tf.zeros(shape, dtype=tf.float32, name=None)
Explanation:
shape: A list of integers, a tuple of integers, or a 1-D Tensor of type int32.
dtype: The type of an element in the resulting Tensor.
name: A name for the operation (optional).
'''
W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = tf.matmul(W, x_data) + b # Minimize variance
''' tf.square(x, name=None)
Explanation:
Computes square of x element-wise.
'''
''' tf.reduce_mean(input_tensor, axis=None, keepdims=None, name=None, reduction_indices=None, keep_dims=None)
Explanation:
input_tensor: The tensor to reduce. Should have numeric type.
axis: The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range
[-rank(input_tensor), rank(input_tensor)].
keepdims: If true, retains reduced dimensions with length 1.
name: A name for the operation (optional).
reduction_indices: The old (deprecated) name for axis.
keep_dims: Deprecated alias for keepdims.
'''
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.5)
train = optimizer.minimize(loss) # Initialize variables
init = tf.initialize_all_variables() # Launch the graph in a session.
sess = tf.Session()
sess.run(init) # Fitting
for step in range(0, 201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b)) # The best fitting result: W = [[0.10000069 0.20000069]], b = [0.29999927]
Tensorflow - Implement for generating some 3-dimensional phony data and fitting them with a plane.的更多相关文章
- Tensorflow - Implement for a Convolutional Neural Network on MNIST.
Coding according to TensorFlow 官方文档中文版 中文注释源于:tf.truncated_normal与tf.random_normal TF-卷积函数 tf.nn.con ...
- Tensorflow - Implement for a Softmax Regression Model on MNIST.
Coding according to TensorFlow 官方文档中文版 import tensorflow as tf from tensorflow.examples.tutorials.mn ...
- ubuntu14.04 安装 tensorflow
如果内容侵权的话,联系我,我会立马删了的-因为参考的太多了,如果一一联系再等回复,战线太长了--蟹蟹给我贡献技术源泉的作者们- 最近准备从理论和实验两个方面学习深度学习,所以,前面装好了Theano环 ...
- #tensorflow入门(1)
tensorflow入门(1) 关于 TensorFlow TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操 ...
- CentOS 7 下使用虚拟环境Virtualenv安装Tensorflow cpu版记录
1.首先安装pip-install 在使用centos7的软件包管理程序yum安装python-pip的时候会报一下错误: No package python-pip available. Error ...
- 蛙蛙推荐: TensorFlow Hello World 之平面拟合
tensorflow 已经发布了 2.0 alpha 版本,所以是时候学一波 tf 了.官方教程有个平面拟合的类似Hello World的例子,但没什么解释,新手理解起来比较困难. 所以本文对这个案例 ...
- [Tensorflow] Cookbook - The Tensorflow Way
本章介绍tf基础知识,主要包括cookbook的第一.二章节. 方针:先会用,后定制 Ref: TensorFlow 如何入门? Ref: 如何高效的学习 TensorFlow 代码? 顺便推荐该领域 ...
- TensorFlow在windows10上的安装与使用(一)
随着近两年tensorflow越来越火,在一台新win10系统上装tensorflow并记录安装过程.华硕最近的 Geforce 940mx的机子. TensorFlow是一个采用数据流图(data ...
- Win10 TensorFlow(gpu)安装详解
Win10 TensorFlow(gpu)安装详解 写在前面:TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统,其命名来源于本身的运行原理.Tensor(张量)意味着 ...
随机推荐
- 编译问题: "ld: duplicate symbol _OBJC_METACLASS_$_XXX..."
在新的SDK环境中调试百度地图的应用程序时,app总是意外退出,找了半天发现错误的原因是unrecognized selector xx的错误,另外还有报了一个Unknown class XXX in ...
- jQuery入门简单实现反选与全选
//html代码<input type="checkbox" id= 'all' value="全选"> 选择全部 一键上路 <input t ...
- 利用MyFlash闪回丢失数据
MyFlash is an open source tool released by Meituan-Dianping which can be used to flashback MyS ...
- SpringBoot整合Mybatis,TypeAliases配置失败的问题
SpringBoot整合Mybatis,TypeAliases配置失败的问题 问题描述 在应用MyBatis时,使用对象关系映射,将对象和Aliase映射起来. 在Mybatis的文档明确写出,如果你 ...
- Python图像处理:图像腐蚀与图像膨胀
图像的膨胀(Dilation)和腐蚀(Erosion)是两种基本的形态学运算,主要用来寻找图像中的极大区域和极小区域.其中膨胀类似于“领域扩张”,将图像中的高亮区域或白色部分进行扩张,其运行结果图比原 ...
- Final,finally,finalize区别
final— 修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能既被声明为 abstract的,又被声明为final的.将变量或方法声明为f ...
- SSH Secure :Algorithm negotiation failed,反复提示输入password对话框
在嵌入式开发中,SSH Secure File Transfer Client 软件使用,方便了windows和linux之间文件拷贝,尤其是多台主机状况下. 最近装了Ubuntu 16.0.4,在V ...
- Go正则处理
Go语言通过regexp标准包为正则表达式提供了官方支持 包中有三个函数判定是否匹配,匹配返回true,否则返回false,这三个函数只是输入源不同 func Match(pattern string ...
- ACM1004:Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- C语言中字符串赋值的几个理解
在C语言中,字符串的赋值主要有两种方法,第一种是通过指针的方式直接赋值,第二种是通过数组直接赋值. 一.首先,我们来看第一种赋值方法:指针式赋值 我们知道,上面的示例是显然可以正常执行的,也是很容易理 ...