9
我不能完全理解theano.scan()的行爲。Python - Theano掃描()函數
下面是一個例子:
import numpy as np
import theano
import theano.tensor as T
def addf(a1,a2):
return a1+a2
i = T.iscalar('i')
x0 = T.ivector('x0')
step= T.iscalar('step')
results, updates = theano.scan(fn=addf,
outputs_info=[{'initial':x0, 'taps':[-2]}],
non_sequences=step,
n_steps=i)
f=theano.function([x0,i,step],results)
print f([1,1],10,2)
上面片斷輸出按照以下順序,它是完全合理的:
[ 3 3 5 5 7 7 9 9 11 11]
然而如果切換抽頭索引從-2至-1,即
outputs_info=[{'initial':x0, 'taps':[-1]}]
結果變成:
[[ 3 3]
[ 5 5]
[ 7 7]
[ 9 9]
[11 11]
[13 13]
[15 15]
[17 17]
[19 19]
[21 21]]
,而不是什麼似乎合理的,我(只取向量的最後一個值,並添加2):
[ 3 5 7 9 11 13 15 17 19 21]
任何幫助將非常感激。
謝謝!