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(张量)意味着 ...
随机推荐
- Java日期类题目
每类题都有各种各样解决的方式,大家随意发散 分析以下需求,并用代码实现 1.已知日期字符串:"2015-10-20",将该日期字符串转换为日期对象 2.将(1)中的日期对象转换为日 ...
- lead over 和 lag over
今天在熟悉项目的某个功能模块时,查看mybatis的映射文件内发现这样的一串sql: (T.NET_VALUE - LEAD(T.NET_VALUE)OVER(ORDER BY T.ESTIMATE_ ...
- Zabbix——部署(agent和proxy安装)
前提条件: 已经完成对Zabbix-server的安装 已经完成对Mysql的安装 并且相互和正常使用和访问 配置agent服务器: rpm -Uvh https://repo.zabbix.com/ ...
- CYQ MAction,子表 新增,删除,修改 集合
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- Java中Date类型如何向前向后滚动时间,( 附工具类)
Java中的Date类型向前向后滚动时间(附工具类) 废话不多说,先看工具类: import java.text.SimpleDateFormat; import java.util.Calendar ...
- 导入jar包和创建jar文件
具体步骤 导入jar包 1.在第一个工程中编写工具类并运行生成.class文件 2.在myeclipse工具栏找到open in 文件夹图标找到.class文件所在的包,将其全部复制到某个盘符下( ...
- Linux phpmailer发送邮件失败的解决方法
(本地windows phpmailer发送ok 放到linux发送失败) 原因:linux 通过465端口进行更安全的SMTPS协议发送邮件 windows 是基于smtp 25端口的 因此 可 ...
- 集合之HashMap、Hashtable
HashMap 基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了非同步和允许使用 null 之外,HashMap 类与 Hashtabl ...
- 用matplotlib库画图
1.用例一 import matplotlib.pyplot as plt import numpy as np x=np.linspace(0,10,100) y=np.cos(2*np.pi*x) ...
- Python学习:9.模块的安装以及调用模块
什么是模块 在Python中,模块其实也就是包含python代码的文件,我们为什么要使用模块?在我们以后写代码的时候,我们会发现有很多功能需要经常使用,那我们想要使用这些功能怎么办,要再把那些代码在敲 ...