I believe I might be approaching this the wrong way. I wanted to index pm.Data
using the output from a random variable (RV) within the model, but the random variable appears to be stuck at a single value, indicating that it’s not sampling properly. Here’s an example of the code I used (there are also some warning generated in the logs):
import numpy as np
import pymc as pm
import pytensor.tensor as pt
import pytensor
import arviz as az
import seaborn as sns
with pm.Model() as m:
mean_sales = pm.MutableData("mean_sales",[100, 0., 50000])
categories = pm.Categorical("categories", p=[0.33, 0.33, 0.34])
sales = pm.Normal("sales",mu=mean_sales[categories],sigma=1) #i <<-indexing here
idata=pm.sample(10000)
Sampling 2 chains, 0 divergences ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00 / 0:00:20
/usr/local/lib/python3.11/dist-packages/arviz/stats/diagnostics.py:596:
RuntimeWarning: invalid value encountered in scalar divide
(between_chain_variance / within_chain_variance + num_samples - 1) / (num_samples)
When I plot the posterior samples from the random variable categories
, it appears to be stuck at a single value which has similar effects on its descendant nodes.