theano.scan()原型:
theano.scan(
fn,
sequences=None,
outputs_info=None,
non_sequences=None,
n_steps=None, truncate_gradient=-1,
go_backwards=False,
mode=None,
name=None,
profile=False,
allow_gc=None,
strict=False
)
fn:一个函数,要求scan的每一个步骤都需要执行这个函数,可以有多个参数,对应于scan其他几个参数,例,如下调用:
scan(fn,
sequences = [ dict(input= Sequence1, taps = [-3,2,-1]),
Sequence2,
dict(input = Sequence3, taps = 3) ],
outputs_info = [ dict(initial = Output1, taps = [-3,-5]),
dict(initial = Output2, taps = None),
Output3 ],
non_sequences = [ Argument1, Argument2])
fn函数的参数列表为如下顺序, t表示当前迭代:
1. Sequence1[t-3]
2. Sequence1[t+2]
3. Sequence1[t-1]
4. Sequence2[t]
5. Sequence3[t+3]
6. Output1[t-3]
7. Output1[t-5]
8. Output3[t-1]
9. Argument1
10. Argument2
当fn的参数个数与scan的sequences,outputs_info,non_sequences参数不符合时会报错。
sequences,每次迭代取一个元素,从名字上也可以看出这个参数的意图,一串数据,一个一个来处理。
outputs_info,把fn的当次输出作为下次迭代的输入,那么第一次迭代没有输出咋整,这个参数就是用来初始化第一次输出的。outputs_info
, must be of a shape similar to that of the output variable generated at each iteration and moreover, it must not involve an implicit downcast of the latter.
non_sequences,看名字能看出来它不是序列,也就是每次迭代都用这个元素。
taps,可以看作是“分别从序列的那个位置开始”
The general order of function parameters to fn is :
sequences (if any), prior result(s) (if needed), non-sequences (if any)