Multidimensional Variables

Hi! I’m working in some Multinomial regression where the model is to be continuously updated with new observations.
I’ve intended to use the Interpolated constructor to build priors for the multinomial probabilities from the previously sampled model. I came up with the following function to build my model:

def from_posterior(param:str, samples:np.ndarray, shape:tuple):

    smin, smax = np.min(samples), np.max(samples)
    width = smax - smin
    x = np.linspace(smin, smax, 100)
    y = stats.gaussian_kde(samples)(x)
    x = np.concatenate([[x[0] - 0.01 * width], x, [x[-1] + 0.1 * width]])
    y = np.concatenate([[0], y, [0]])
    return pm.Interpolated(param, x, y, shape = shape)

def model_from_posterior(number_of_outcomes:int, 
                         observed_data:pd.Series, 
                         prior_data:az.InferenceData)->pm.Model:

    total_observations = observed_data.sum()    
    with pm.Model() as model:
        probs = []
        for i, sample in enumerate(prior_data['probs'].T):
            probs.append(from_posterior(f'probs_{i}', sample, (1,)))

        probs = tt.as_tensor_variable(probs)
        likelihood = pm.Multinomial(
            'observed_values', n=total_observations, 
             p=probs,
             observed=observed_data)
    return model

My question is: How do I transform probs a multidimensional variable using theano for plotting purposes and are there any recommendations for plotting these kind of models?

How do I transform probs a multidimensional variable using theano for plotting purposes

We may need a little clarification to give you specific help here. If your main issue is that you would like to get the actual values of probs for plotting, you can use the Deterministic object to make sure that values of probs are stored in your trace. However, you could also get the same effect by just not overwriting the non-Theano typed variable probs by changing the line probs = tt.as_tensor_variable(probs) to use a different name.