Must be real number, not FreeRV

I have som trouble with my model in pymc3. My main code looks like this:

with pm.Model() as RAA_Eloss:

    #Priors
    a = Normal('a', mu=10, sigma=30)
    b = Normal('b', mu=10, sigma=30)
    c = Normal('c', mu=1, sigma=10)

    mu = RAA_model(a, b, c, RAA_x, RAA_y, RAA_xerr, RAA_yerr, pp_pt, PPspectra)

    likelihood = Normal('likelihood', mu=mu, tau=1/(RAA_yerr)**2, observed=RAA_y)
    trace = pm.sample(draws=5000, tune=1000, chains=4, return_inferencedata=True)
    az.plot_trace(trace);

And the function RAA_model:

def RAA_model(a, b, c, RAA_x, RAA_y, RAA_xerr, RAA_yerr, pt, pp_spectra):
    intg_res = np.zeros_like(RAA_x)
    pp_fit = interp1d(pt, pp_spectra, fill_value="extrapolate")
    for i, x in enumerate(gala30x):
        # integral DeltaPt from 0 to infinity
        scale_fct = RAA_x / gala30x[-1]
        x = x * scale_fct
        shifted_pt = RAA_x + x
        mean_dpt = mean_ptloss(shifted_pt, b, c)
        alpha = a
        beta = a / mean_dpt
        pdpt = Eloss_func(x, alpha, beta)
        intg_res += scale_fct*gala30w[i]*pdpt*pp_fit(shifted_pt)
    return intg_res/pp_fit(RAA_x)

The problem is in the function Eloss_func(x, alpha, beta):

def Eloss_func(x, alpha, beta):
    return beta**(alpha)*np.exp(-beta*x)*x**(alpha-1)/math.gamma(alpha)

It seem to be with math.gamma(alpha), I get the following error: must be real number, not FreeRV
How can in fix this?

Looks like you need an implementation of math.gamma that works symbolically.
You can probably just replace it with theano.tensor.gamma. For PyMC v4 it will be at.gamma.

Thank you! That worked!

thanks for the awesome information.