import pytensor.tensor as pt
import numpy as np
import pymc as pm
file_path = 'Combination.xlsx'
df = pd.read_excel(file_path, sheet_name = 0, header=None)
Combination_cpt = df.to_numpy().T
Combination_cpt.shape
bins = np.array([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120])
# num_states_plf = len(bins) - 1
# num_states_slf = len(bins) - 1
Combination_cpt_tensor = pt.as_tensor_variable(Combination_cpt)
with pm.Model() as model:
PoA = pm.Triangular('PoA', lower=0, c=0.3, upper=1)
CF = pm.Lognormal('CF', mu=4.5, sigma=0.2)
TEF = pm.Deterministic('TEF', CF * PoA)
vulnerability = pm.Normal('vulnerability', mu=1, sigma=0.5)
MPLEF = pm.Deterministic('MPLEF', TEF * vulnerability)
CoSL = pm.Normal('CoSL', mu=0.7, sigma=0.2)
PLF = pm.Poisson('PLF', mu=MPLEF)
SLF = pm.Binomial('SLF', n=PLF, p=CoSL)
plf_bin = pt.searchsorted(bins, PLF) - 1
slf_bin = pt.searchsorted(bins, SLF) - 1
def get_cpt_value_combination(plf_state, slf_state, cpt_tensor):
idx = plf_state * 12 + slf_state
return cpt_tensor[idx]
p_Combination = get_cpt_value_combination(plf_bin, slf_bin, Combination_cpt_tensor)
Combination = pm.Categorical('Combination', p=p_Combination)
trace = pm.sample(10000, tune=1000)
Thank you for your suggestions!! I tried converting the CPTs into tensors in advance and also followed your advice. However, sampling from the Combination node is still not working. Are there any other issues that could be causing this?