有关Theano和PyTensor库

根据Github里面的介绍,PyTensor是源于Theano, Theano目前应该已经不再开发了,更新都是很多年前。 因此PyTensor在背景介绍中说

PyTensor is a fork of Aesara, which is a fork of Theano.

Theano和PyTensor都是计算相关的库,可以在CPU、GPU结构中进行计算。使用也非常相似

PyTensor目前用作PyMC的计算后端。

python 复制代码
import theano
from theano import tensor

# Declare two symbolic floating-point scalars
a = tensor.dscalar()
b = tensor.dscalar()

# Create a simple expression
c = a + b

# Convert the expression into a callable object that takes (a, b)
# values as input and computes a value for c
f = theano.function([a, b], c)

# Bind 1.5 to 'a', 2.5 to 'b', and evaluate 'c'
assert 4.0 == f(1.5, 2.5)
python 复制代码
import pytensor
from pytensor import tensor as pt

# Declare two symbolic floating-point scalars
a = pt.dscalar("a")
b = pt.dscalar("b")

# Create a simple example expression
c = a + b

# Convert the expression into a callable object that takes `(a, b)`
# values as input and computes the value of `c`.
f_c = pytensor.function([a, b], c)

assert f_c(1.5, 2.5) == 4.0