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.的更多相关文章

  1. Tensorflow - Implement for a Convolutional Neural Network on MNIST.

    Coding according to TensorFlow 官方文档中文版 中文注释源于:tf.truncated_normal与tf.random_normal TF-卷积函数 tf.nn.con ...

  2. Tensorflow - Implement for a Softmax Regression Model on MNIST.

    Coding according to TensorFlow 官方文档中文版 import tensorflow as tf from tensorflow.examples.tutorials.mn ...

  3. ubuntu14.04 安装 tensorflow

    如果内容侵权的话,联系我,我会立马删了的-因为参考的太多了,如果一一联系再等回复,战线太长了--蟹蟹给我贡献技术源泉的作者们- 最近准备从理论和实验两个方面学习深度学习,所以,前面装好了Theano环 ...

  4. #tensorflow入门(1)

    tensorflow入门(1) 关于 TensorFlow TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操 ...

  5. CentOS 7 下使用虚拟环境Virtualenv安装Tensorflow cpu版记录

    1.首先安装pip-install 在使用centos7的软件包管理程序yum安装python-pip的时候会报一下错误: No package python-pip available. Error ...

  6. 蛙蛙推荐: TensorFlow Hello World 之平面拟合

    tensorflow 已经发布了 2.0 alpha 版本,所以是时候学一波 tf 了.官方教程有个平面拟合的类似Hello World的例子,但没什么解释,新手理解起来比较困难. 所以本文对这个案例 ...

  7. [Tensorflow] Cookbook - The Tensorflow Way

    本章介绍tf基础知识,主要包括cookbook的第一.二章节. 方针:先会用,后定制 Ref: TensorFlow 如何入门? Ref: 如何高效的学习 TensorFlow 代码? 顺便推荐该领域 ...

  8. TensorFlow在windows10上的安装与使用(一)

    随着近两年tensorflow越来越火,在一台新win10系统上装tensorflow并记录安装过程.华硕最近的 Geforce 940mx的机子. TensorFlow是一个采用数据流图(data ...

  9. Win10 TensorFlow(gpu)安装详解

    Win10 TensorFlow(gpu)安装详解 写在前面:TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统,其命名来源于本身的运行原理.Tensor(张量)意味着 ...

随机推荐

  1. Oracle 11gR2 RAC 11.2.0.4 全自动打11.2.0.4.20170418 psu 步骤

    说明:此次环境的patch p6880880_112000_Linux-x86-64.zip 和 p25476126_112040_Linux-x86-64.zip均放在/soft目录, 且grid和 ...

  2. Oracle 11g监听器配置

    Oracle 11g监听器配置 安装好oracle后,出现oracle监听器不能正确使用的问题,先后遇到问题: 1.Oracle ORA-12541:TNS:no listener 2.ORA-285 ...

  3. Java并发编程(一)为什么要并发

    并发所带来的好处 1. 并发在某些情况(并不是所有情况)下可以带来性能上的提升 1) 提升对CPU的使用效率 提升多核CPU的利用率:一般来说一台主机上的会有多个CPU核心,我们可以创建多个线程,理论 ...

  4. MySQL学习之用户管理

    用户权限管理 用户权限管理:在不同的项目中给不同的角色(开发者)不同的操作权限,为了保证数据库数据的安全. 简单点说:有的用户可以访问并修改这个数据,而有些用户只能去查看数据,而不能修改数据.就如同博 ...

  5. Systemd简介与使用

    按下电源键,随着风扇转动的声音,显示器上开启的图标亮起.之后,只需要静静等待几秒钟,登录界面显示,输入密码,即可愉快的玩耍了. 这是我们大概每天都做的事情.那么中间到底发生了什么? 简单地说,从BIO ...

  6. Django的MVT的思路

    1.先上两张图片 2.我的理解 view在MVT框架里面,起到的是中间调度的作用. a.在diango里面有个关键性路径的配置 就是在django2.0前的url和在2.0后的path. 为避免一个项 ...

  7. javascript最常用的对象创建方式

    //第一种 function Demo(){ var obj=new Object(); obj.name="Yubaba"; obj.age=12; obj.firstF=fun ...

  8. pm2命令管理启动的nodejs项目进程

    安装 npm install -g pm2 用法 $ npm install pm2 -g # 命令行安装 pm2 $ pm2 start app.js -i 4 #后台运行pm2,启动4个app.j ...

  9. php的基础知识(一)

    php(超文本预处理器)定义: php(外文名:php:Hertext Preprocessor,中文名:“超文本预处理器”)是一种通用的开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于 ...

  10. 大数据技术原理与应用——大数据处理架构Hadoop

    Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台,为用户提供了系统底层细节透明的分布式基础架构. Hadoop是基于Java语言开发的,具有很好的跨平台特性,并且可以 ...