Theano 2D直方图

时间:2017-08-10 02:43:34

标签: python theano

theano抱怨x0在我尝试使用它来计算2D直方图时从不使用。

fththeano实施,不起作用。 fnpnumpy实现,可以按预期工作。

import theano
import theano.tensor as T
import numpy as np
def fth(a,b,c):
    x0 = T.lvector('x0')
    x1 = T.lvector('x1')
    z = T.lvector('z')

    x1 *= x0.size
    x0 += x1
    T.subtensor.AdvancedIncSubtensor1(z, x0)
    f = theano.function([x0, x1, z], z)
    return f(a, b, c, on_unused_input='ignore')

def fnp(a, b, c):
    np.add.at(c, a+b*a.size, 1)
    return c

a = np.array([0, 1, 2, 3], dtype=np.int64)
b = np.array([0, 1, 0, 1], dtype=np.int64)
c = np.zeros(16, dtype=np.int64)
print(fnp(a, b, c))
print(fth(a, b, c))

错误:

theano.compile.function_module.UnusedInputError: theano.function
was asked to create a function computing outputs given certain 
inputs, but the provided input variable at index 0 is not part of 
the computational graph needed to compute the outputs: 

    Elemwise{add,no_inplace}.0.

To make this error into a warning, you can pass the parameter 
on_unused_input='warn' to theano.function. To disable it 
completely, use on_unused_input='ignore'.

0 个答案:

没有答案