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. Python 学习笔记(九)Python元组和字典(二)

    什么是字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 键必须是唯 ...

  2. MyBatis之properties配置

    这些属性都是可外部配置且可动态替换的,既可以在典型的 Java 属性文件中配置,亦可通过 properties 元素的子元素来传递.例如: <properties resource=" ...

  3. 理解AndroidX

    理解AndroidX 刚刚看到自己加的一个Android群里有人问AndroidX,还是Google自己的,竟然没听说过,慌的一匹.赶紧去看了下官方文档和一些博客,对AndroidX有了如下理解 An ...

  4. SQL 二

    1.执行DML语句的步骤:在数据库缓冲区缓存中搜索相关的块:将块从数据文件复制到缓冲区:将变更向量写入日志缓冲区:将变更向量应用于数据库缓冲区缓存.2.重做可以保护的段类型:索引段.表段.撤销段.3. ...

  5. HTML中IMG标签总结

    一.Img标签有两个重要的属性: 1.src  属性:图片的地址 2.alt  属性:图片不显示是现实的文字 二.Img标签是行级元素: img.input属于行内替换元素.height/width/ ...

  6. 复习宝典之Git分布式版本控制

    查看更多宝典,请点击<金三银四,你的专属面试宝典> 第三章:Git分布式版本控制 1)git文件状态 git中的文件有以下几种状态: 未跟踪(untrack):表示文件为新增加的. 已修改 ...

  7. Spring Boot在反序列化过程中:jackson.databind.exc.InvalidDefinitionException cannot deserialize from Object value

    错误场景 用Spring boot写了一个简单的RESTful API,在测试POST请求的时候,request body是一个符合对应实体类要求的json串,post的时候报错. 先贴一段error ...

  8. C语言之二叉树

    规定:根节点的值大于左节点但小于右节点的值,所以二叉树的值插入是唯一的,最后形成的树只跟根节点有关 定义节点: struct tree_node {      TypeElem  elem; stru ...

  9. 从零开始一个http服务器(四)-动态返回

    从零开始一个http服务器(四) 代码地址 : https://github.com/flamedancer/cserver git checkout step4 运行: make clean &am ...

  10. Java异常链

    是什么 一种面向对象的编程技术,将捕获到的异常重新封装到一个新的异常中,并重新抛出. 有什么用 可以保留每一层的异常信息,用户查看异常的时候,能够从顶层异常信息看到底层异常信息. 怎么用 catch异 ...