I'm trying desperately to understand the taps argument in the theano.scan function. Unfortunately I'm not able to come up with a specific question.
I just don't understand the "taps" mechanism. Well I ok. I know in which order the sequences are passed to the function, but I don't know the meaning. For example (I borrowed this code from another Question Python - Theano scan() function):
import numpy as np
import theano
import theano.tensor as T
def addf(a1,a2):
print(a1)
print(a2)
return a1+a2
i = T.iscalar('i')
x0 = T.ivector('x0')
step= T.iscalar('step')
results, updates = theano.scan(fn=addf,
outputs_info=[dict(initial=x0, taps=[-3])],
non_sequences=step,
n_steps=i)
f=theano.function([x0, step,i],results)
input = [2, 3]
print(f(input, 2, 20))
Setting taps to -1 does make sense to me. As far as I understand it's the same as not setting the taps value and the whole vector 'x0' is being passed to the addf function. x0 will then be added with the "step" parameter (int 2 which will be broadcasted to the same size). In the next iteration the result [4, 5] will be the input and so on which yields the following output:
[[ 4 5]
[ 6 7]
[ 8 9]
[10 11]
[12 13]
[14 15]
[16 17]
[18 19]
[20 21]
[22 23]
[24 25]
[26 27]
[28 29]
[30 31]
[32 33]
[34 35]
[36 37]
[38 39]
[40 41]
[42 43]]
Setting taps to -3 however yields the following output:
[ 5 2 6 7 4 8 9 6 10 11 8 12 13 10 14 15 12 16 17]
I don't have any explanation how the scan function creates this output. Why is it just a list now? The "print(a1)" turns out to be as expected
x0[t-3]
Although I know that this is the value that a1 should have, I do not know how to interpret it. What is the t-3 th value of x0? The theano documentation doesn't seem to be all to detailed about the taps argument... so hopefully one of you guys will be.
Thx