tensorflow学习笔记及课后习题
Tensorflow是什么?
TensorFlow是一个用于数值计算的强大开源软件库, 非常适合大型机器学习。 它背后的原理很简单: 首先在Python中定义一个用来计算的图 , 然后TensorFlow就会使用这个图, 并用优化过的C++代码来执行计算。
Tensorflow的优势
提供了一个非常简单的名叫TF.Learn(tensorflow.contrib.learn)的Python API来兼容Scikit-Learn。
可以将计算图分解进行并行计算。
提供另一个叫作TF-Slim(tensorflow.contrib.slim)的简单API来简化神经网络的构建、 训练和评估。
在TensorFlow之上, 独立构建了一些高级的API, 比如Keras(http://keras.io) 和PrettyTensor(https://github.com/google/prettytensor/) 。
提供一个非常强大的叫作TensorBoard的可视化工具。
tensorflow测试样例:
- import tensorflow as tf
a = tf.constant([1.0,2.0],name="a")
b = tf.constant([2.0,3.0],name="b")
result = a + b
sess = tf.Session()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> sess.run(result)
array([ 3., 5.], dtype=float32 - >>> type(result)
<class 'tensorflow.python.framework.ops.Tensor'> -
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-
import tensorflow as tf
import numpy as np
a=tf.constant(2,name="a")
b=tf.constant(4,name="b")
result=a+b
print(result)
sess=tf.Session()
print("the result is ",sess.run(result)) - 输出结果:the result is 6
课后习题 4.7:
2、简答题:
(1)1、可以充分逼近任意复杂的非线性关系;
2、所有定量或定性的信息都等势分布贮存于网络内的各神经元,故有很强的鲁棒性和容错性;
3、采用并行分布处理方法,使得快速进行大量运算成为可能;
4、可学习和自适应不知道或不确定的系统;
5、能够同时处理定量、定性知识。
(2)BP神经网络具有任意复杂的模式分类能力和优良的多维函数映射能力,解决了简单感知器不能解决的异或(Exclusive OR,XOR)和一些其他问题。
3、论述题:
1、1、前馈神经网络只接受上一层传来的数据,处理然后接着再传入到下一层, 数据是正向流动的,而反馈神经网络神经元之间是由连接的,数据可以反馈到前层。
2、前馈神经网络不考虑输出和输入时间上的延迟,只能表示出输出和输入之间的一个映射关系,而反馈神经网络不同,他会考虑输出和输入之间的延迟,会考虑到输出对输入是否有用。
3、相比较前馈神经网络,反馈神经网络更适合记忆等功能。
2、BP神经网络无论在网络理论还是在性能方面已比较成熟。其突出优点就是具有很强的非线性映射能力和柔性的网络结构。网络的中间层数、各层的神经元个数可根据具体情况任意设定, 并且随 着结构的差异其性能也有所不同。但是BP神经网络也存在以下的一些主要缺陷。
①学习速度慢,即使是一个简单的问题,一般也需要几百次甚至上千次的学习才能收敛。
②容易陷入局部极小值。
③网络层数、神经元个数的选择没有相应的理论指导。
④网络推广能力有限。
3、网络的各个输入数据常常具有不同的物理意义和不同的量纲,如某输入分量在范围内变化,而另一输入分量则在 0~1 10-5范围内变化。尺度变换使所有分量都在 0~1或 -1~1之间变化,从而使网络训练一开始就给各输入分量以同等重要的地位:
BP 网的神经 元均采用Sigmoid 转移函数,变换后可防止因净输入的绝对值过大而使神经元输出饱和, 继 而使权值调整进入误差曲面的平坦区; Sigmoid 转移函数的输出在 0~1或-1 ~1之间,作 为教师信号的期望输出数据如不进行变换处理势必使数值大的分量绝对误差大, 数值小的分量的绝对误差小,网络训练时只针对输出的总误差调整权值,其结果是在总误差中占份额 小的输出分量相对误差较大,对输出分量进行尺度变换后这个问题可迎刃而解。
浙公网安备 33010602011771号