英文:
Problem with TensorVariable type and special functions in pymc
问题
I'm using a pymc model that contains the special function gamma. Since scipy special functions doesn't work with pytensor as variable, I'm trying to escape the problem with an @as_op:
@as_op(itypes=theano.tensor.dscalar, otypes=theano.tensor.dscalar)
def gamma_theano(x):
return scipy.special.gamma(x)
This very naive solution was used to work perfectly with previous projects (and previous package versions), while now I'm getting the error:
TypeError: We expected inputs of types '[TensorType(float64, scalar)]' but got types '[TensorType(float64, ())]'
Suggestions are very well received. Thanks.
英文:
I'm using a pymc model that contains the special function gamma. Since scipy special functions doesn't work with pytensor as variable, I'm trying to escape the problem with an @as_op:
@as_op(itypes=theano.tensor.dscalar, otypes=theano.tensor.dscalar)
def gamma_theano(x):
return scipy.special.gamma(x)
This very naive solution was used to work perfectly with previous projects (and previous package versions), while now I'm getting the error:
TypeError: We expected inputs of types '[TensorType(float64, scalar)]' but got types '[TensorType(float64, ())]'
Suggestions are very well received. Thanks.
答案1
得分: 0
Using pytensor而不是theano解决了错误:
import pytensor
@as_op(itypes=pytensor.tensor.dscalar, otypes=pytensor.tensor.dscalar)
def gamma_theano(x):
return scipy.special.gamma(x)
然而,在我的情况下,这没有解决问题,因为它导致了分段错误。
我使用了pytensor的内置gamma函数找到了解决方案:
import pytensor
pytensor.tensor.math.gamma(x)
英文:
Using pytensor instead of theano resolves the error:
import pytensor
@as_op(itypes=pytensor.tensor.dscalar, otypes=pytensor.tensor.dscalar)
def gamma_theano(x):
return scipy.special.gamma(x)
However, in my case, this didn't solved the issue because it led to a segmentation error.
I've found the solution with the built-in gamma function of pytensor:
import pytensor
pytensor.tensor.math.gamma(x)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论