Search code examples
python-2.7theanotheano.scan

What arguments does "sequences" paramater take in theano.scan and how are they interpreted


I have taken the following code from http://deeplearning.net/software/theano/library/scan.html

    import numpy

    coefficients = theano.tensor.vector("coefficients")
    x = T.scalar("x")

    max_coefficients_supported = 10000

    # Generate the components of the polynomial
    components, updates = theano.scan(fn=lambda coefficient, power, free_variable: coefficient * (free_variable ** power),
                              outputs_info=None,
                              sequences=[coefficients, theano.tensor.arange(max_coefficients_supported)],
                              non_sequences=x)

The code here was meant to explain "sequences" parameter. Here is my question:

  1. How are the sequences fed? The first term "coefficients" is a tensor variable. The second term "theano.tensor.arange(max_coefficients)" is a tensor variable which on using eval() gives a list with [0......999]. The tutorial says-

    "The tensor(s) to be looped over should be provided to scan using the sequence keyword argument."
    

    How is the looping happening here based on the arguments provided here in "sequences"?


Solution

  • The order of the arguments is : sequence[t],outputs_infor,non_sequence

     coefficients[t]
     theano.tensor.arange(max_coefficients_supported)[t]
     x
    

    outputs_infor saves the result of the previous iteration