Call a function from scan in Theano -


i need execute theano function number of times via scan in order sum-up cost function , use in gradient computation. i'm familiar deep-learning tutorials data slicing , other complications means need little different. below simplified version of i'm trying do..

tn = testnet() cost = tn.single_cost( ) x = theano.shared(numpy.asarray([7.1,2.2,3.4], dtype='float32')) index = t.lscalar('index') test_fn = theano.function(inputs=[index], outputs=cost,      givens={tn.x:x[index:index+1]} )  def step(curr):     return t.constant( test_fn( curr ) ) outs,_ = theano.scan(step, t.arange(2))  out_fn = theano.function(inputs=[], outputs=outs) print out_fn() 

in scan function, call test_fn(curr) giving error... expected array-like object, found variable: maybe trying call function on (possibly shared) variable instead of numeric array?')

even if pass in array of values instead of putting t.arrange(2) in place, still same error. there reason can't call function scan?

in general i'm wondering if there way call function series of indexes output can feed t.grad() computation (not shown).

don't make 2 different theano.functions.

a theano.function takes symbolic relationship, optimizes it, , compiles it. doing here asking theano.scan (and out_fn) consider compiled function symbolic relationship. whether technically work i'm not sure, goes against idea of theano.

since don't know cost function here can't give exact example, here's quick example work , should similar enough think you're trying do.

x = theano.shared(np.asarray([7.1,2.2,3.4], dtype = np.float32))  v = t.vector("v") def fv(v):     res,_ = theano.scan(lambda x: x ** 2, v)     return t.sum(res)  def f(i):     return fv(x[i:i+2])  outs,_ = theano.scan(     f,      t.arange(2)     )  fn = theano.function(     [],     outs,     )  fn() 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -