Theano-PyMC

1.1.2 · maintenance · verified Thu Apr 16

Theano-PyMC is a Python library that serves as an optimizing compiler for evaluating mathematical expressions on CPUs and GPUs, featuring efficient symbolic differentiation. It is a fork of the original Theano library, specifically maintained by the PyMC developers to support PyMC3. Its current version is 1.1.2, released in January 2021. While PyMC has since transitioned to other backends (Aesara, then PyTensor), Theano-PyMC remains the foundational backend for PyMC3, meaning its release cadence is tied to critical compatibility and bug fixes for that specific PyMC version.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define symbolic variables, construct a mathematical expression, and compile it into an efficient, callable function using `theano.function`. It also shows the use of `theano.shared` variables, which allow their underlying numerical value to be updated without recompiling the Theano function, crucial for iterative algorithms or fitting models with changing data.

import theano
import theano.tensor as tt
from theano import function

# Define symbolic variables
x = tt.dscalar('x') # A double-precision scalar
y = tt.dscalar('y')

# Define a symbolic expression
z = x ** 2 + y

# Compile the expression into a callable function
f = function([x, y], z)

# Evaluate the function with numerical values
result = f(2.0, 3.0)
print(f"Result of x^2 + y for x=2, y=3: {result}")

# Example with shared variable
import numpy as np
from theano import shared

shared_val = shared(np.array(10.0, dtype=theano.config.floatX), name='shared_val')
output = x * shared_val
g_func = function([x], output)

print(f"Result with shared_val=10 and x=5: {g_func(5.0)}")
shared_val.set_value(np.array(20.0, dtype=theano.config.floatX))
print(f"Result with shared_val=20 and x=5: {g_func(5.0)}")

view raw JSON →