tensorflow学习报告

TensoeFlow函数:tf.where
1 tf.where(input, name=None)`
 2 Returns locations of true values in a boolean tensor.
 3
 4 This operation returns the coordinates of true elements in input. The coordinates are returned in a 2-D tensor where the first dimension (rows) represents the number of true elements, and the second dimension (columns) represents the coordinates of the true elements. Keep in mind, the shape of the output tensor can vary depending on how many true values there are in input. Indices are output in row-major order.
 5
 6 For example:
 7 # 'input' tensor is [[True, False]
 8 #                    [True, False]]
 9 # 'input' has two true values, so output has two coordinates.
10 # 'input' has rank of 2, so coordinates have two indices.
11 where(input) ==> [[0, 0],
12                   [1, 0]]
13
14 # `input` tensor is [[[True, False]
15 #                     [True, False]]
16 #                    [[False, True]
17 #                     [False, True]]
18 #                    [[False, False]
19 #                     [False, True]]]
20 # 'input' has 5 true values, so output has 5 coordinates.
21 # 'input' has rank of 3, so coordinates have three indices.
22 where(input) ==> [[0, 0, 0],
23                   [0, 1, 0],
24                   [1, 0, 1],
25                   [1, 1, 1],
26                   [2, 1, 1]]

 

有两种用法:

1、tf.where(tensor)

tensor 为一个bool 型张量,where函数将返回其中为true的元素的索引。如上图官方注释

2、tf.where(tensor,a,b)

a,b为和tensor相同维度的tensor,将tensor中的true位置元素替换为a中对应位置元素,false的替换为b中对应位置元素。

例:

1
2
3
4
5
6
7
8
9
import tensorflow as tf
import numpy as np
sess=tf.Session()
 
a=np.array([[1,0,0],[0,1,1]])
a1=np.array([[3,2,3],[4,5,6]])
 
print(sess.run(tf.equal(a,1)))
print(sess.run(tf.where(tf.equal(a,1),a1,1-a1)))

 

>>[[true,false,false],[false,true,true]]

>>[[3,-1,-2],[-3,5,6]]

 

 

课后习题:

 4.7

2、简答题:

(1)1、可以充分逼近任意复杂的非线性关系;

     2、所有定量或定性的信息都等势分布贮存于网络内的各神经元,故有很强的鲁棒性和容错性;

     3、采用并行分布处理方法,使得快速进行大量运算成为可能;

     4、可学习和自适应不知道或不确定的系统;

     5、能够同时处理定量、定性知识。

(2)BP神经网络具有任意复杂的模式分类能力和优良的多维函数映射能力,解决了简单感知器不能解决的异或(Exclusive OR,XOR)和一些其他问题。

3、论述题:

1、1、前馈神经网络只接受上一层传来的数据,处理然后接着再传入到下一层, 数据是正向流动的,而反馈神经网络神经元之间是由连接的,数据可以反馈到前层。

      2、前馈神经网络不考虑输出和输入时间上的延迟,只能表示出输出和输入之间的一个映射关系,而反馈神经网络不同,他会考虑输出和输入之间的延迟,会考虑到输出对输入是否有用。
      3、相比较前馈神经网络,反馈神经网络更适合记忆等功能。

2、BP神经网络无论在网络理论还是在性能方面已比较成熟。其突出优点就是具有很强的非线性映射能力和柔性的网络结构。网络的中间层数、各层的神经元个数可根据具体情况任意设定, 并且随                     着结构的差异其性能也有所不同。

3、网络的各个输入数据常常具有不同的物理意义和不同的量纲,如某输入分量在范围内变化,而另一输入分量则在 0~1 10-5范围内变化。尺度变换使所有分量都在 0~1或 -1~1之间变化,从而使网络训练一开始就给各输入分量以同等重要的地位:
BP 网的神经 元均采用Sigmoid 转移函数,变换后可防止因净输入的绝对值过大而使神经元输出饱和, 继 而使权值调整进入误差曲面的平坦区; Sigmoid 转移函数的输出在 0~1或-1 ~1之间,作 为教师信号的期望输出数据如不进行变换处理势必使数值大的分量绝对误差大, 数值小的分量的绝对误差小,网络训练时只针对输出的总误差调整权值,其结果是在总误差中占份额 小的输出分量相对误差较大,对输出分量进行尺度变换后这个问题可迎刃而解。

 6.5

(1)卷积中的局部连接:层间神经只有局部范围内的连接,在这个范围内采用全连接的方式,超过这个范围的神经元则没有连接;连接与连接之间独立参数,相比于去全连接减少了感受域外的连接,有效减少参数规模。全连接:层间神经元完全连接,每个输出神经元可以获取到所有神经元的信息,有利于信息汇总,常置于网络末尾;连接与连接之间独立参数,大量的连接大大增加模型的参数规模。

posted @ 2022-04-24 21:34  啊语  阅读(41)  评论(0)    收藏  举报