Theano: implementing an integral function

∥☆過路亽.° 提交于 2020-01-05 04:41:08

问题


I am trying to implement this function in theano. This is not about solving the integral (which is immediate) but rather how to implement it. So far I have gotten this

import theano
from theano import tensor as T
import numpy as np
import scipy.integrate as integrate

x = T.vector('x')
h = T.vector('h')
t = T.scalar('t')

A = np.asarray([[0,1],[1,0]])       
A = theano.shared(name='A', value=A)  

B = np.asarray([[-1,0],[0,-1]])       
B = theano.shared(name='B', value=B)

xn = A.dot(x)
hn = B.dot(h)

res = (t + xn.dot(hn))**(-2)
g = theano.function([t,x,h],res) # this computes the integrand

f = theano.function([x,h], integrate.quad(lambda t: g(t,x,h), 10, np.inf))

Unfortunately, this doesn't work. I am getting the error missing 2 required positional arguments: 'x' and 'h'. Maybe the integrate.quad function cannot "see" the inputs x,h.

Thanks a lot for the help!

来源:https://stackoverflow.com/questions/38305738/theano-implementing-an-integral-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!