It appears to be impossible to use a random variable as the observed for another variable. For example, consider this simple model:
import pymc3 as pm
import matplotlib.pyplot as plt
import scipy.stats as stats
import numpy as np
raw_observed = 0.3
with pm.Model() as model:
alpha = pm.Exponential('alpha', 0.2)
beta = pm.Exponential('beta', 0.2)
raw_with_slight_adjustment = pm.Normal(
'raw_with_slight_adjustment', raw_observed, 0.0001)
wpp = pm.Beta(
'wpp', alpha=alpha, beta=beta,
observed=raw_with_slight_adjustment)
This model raises a TypeError:
If the observed is a deterministic instead of a RV, the model can be defined. For example this variation of the above does not raise an error:
raw_observed = 0.3
with pm.Model() as model:
alpha = pm.Exponential('alpha', 0.2)
beta = pm.Exponential('beta', 0.2)
slight_adjustment = pm.Normal('slight_adjustment', 0, 0.0001)
raw_with_slight_adjustment = pm.Deterministic(
'raw_with_slight_adjustment',
raw_observed + slight_adjustment)
wpp = pm.Beta(
'wpp', alpha=alpha, beta=beta,
observed=raw_with_slight_adjustment)
But this new model does raise an error when the prior predictives are sampled:
Is using a variable as observed for another variable just a bad idea? Or is this a sensible feature that just has not yet been implemented?
PyMC v3.9.3