Theano: Support numeric integration through a quad function

Created on 27 Oct 2015  Â·  4Comments  Â·  Source: Theano/Theano

Would it be possible with the current framework to have an integration operator quad that works as in the following example?

from theano import function
import theano.tensor as T

x = T.dscalar('x')
y = T.dscalar('y')
expr = T.quad(y * x**2, x, 0, 1)

f = function([y], expr)
# f(y) now evaluates to approx. 1/3 * y

Note that it gets passed an expression as its first argument, and that the variable x does not need to be passed in the call to function.
On the C side, the expression would probably have to be compiled into its own function in the same compilation module, which can then be passed to an integration routine.

Do you think that it would currently be possible to implement this as an operator in Theano?
I yes I would like to give it a try. This would be very useful for me, but I don't have a lot of experience with Theano internals (yet).

Most helpful comment

It's supposed to be a function for numeric integration like this one in scipy: https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.integrate.quad.html

The parameters are:

  1. The expression to integrate
  2. The variable to integrate over
  3. The lower limit of the integration
  4. The upper limit of the integration

This would be different from grad in the sense that the expression needs to be compiled so it can be called by some integration function written in C (for example from GSL or QUADPACK).
The result of that function call would be passed back into the actual Theano expression we want to evaluate.

I guess an alternative would be to return a Theano graph that implements the numeric integral.
But I think it would make sense to rely on some existing implementation, as these can be quite tricky. (It's more complicated than numeric/automatic differentiation).

All 4 comments

I don't understand what quad should do. But you can implement python
function that generate Theano graph like we did with grad, Rop, Lop,
hessian, ...

Also, what do you mean by integration operation? What are the numbers in
the second and third parameter of quad?

On Tue, Oct 27, 2015 at 11:37 AM, Igor Babuschkin [email protected]
wrote:

Would it be possible with the current framework to have an integration
operator quad that works as in the following example?

from theano import functionimport theano.tensor as T

x = T.dscalar('x')
y = T.dscalar('y')
expr = T.quad(y * x**2, x, 0, 1)

f = function([y], expr)# f(y) now evaluates to approx. 1/3 * y

Note that it gets passed an expression as its first argument, and that the
variable x does not need to be passed in the call to function.
On the C side, the expression would probably have to be compiled into its
own function in the same compilation module, which can then be passed to an
integration routine.

Do you think that it would currently be possible to implement this as an
operator in Theano?
I yes I would like to give it a try. This would be very useful for me, but
I don't have a lot of experience with Theano internals (yet).

—
Reply to this email directly or view it on GitHub
https://github.com/Theano/Theano/issues/3564.

It's supposed to be a function for numeric integration like this one in scipy: https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.integrate.quad.html

The parameters are:

  1. The expression to integrate
  2. The variable to integrate over
  3. The lower limit of the integration
  4. The upper limit of the integration

This would be different from grad in the sense that the expression needs to be compiled so it can be called by some integration function written in C (for example from GSL or QUADPACK).
The result of that function call would be passed back into the actual Theano expression we want to evaluate.

I guess an alternative would be to return a Theano graph that implements the numeric integral.
But I think it would make sense to rely on some existing implementation, as these can be quite tricky. (It's more complicated than numeric/automatic differentiation).

The inability to perform numeric integration within the Theano framework is derailing any projects in which I need to compute a complicated integral e.g. to define the likelihood.

Is this something being considered for development?

Unfortunately, active development of Theano by MILA has stopped after the 1.0 release, see https://groups.google.com/forum/#!msg/theano-users/7Poq8BZutbY/rNCIfvAEAwAJ .

Was this page helpful?
0 / 5 - 0 ratings