Serial Dilution Example


I’m trying to recreate the serial dilution example in Chapter 19.1 of BDA3. I’ve included the data here. My initial setup ignores the dilution error. I just want to get a model running at this point.

The setup is straight forward (I believe) with most parameters having a flat or half flat prior. I’m having trouble expressing the mean and variance in a way consistent with the pymc3 API. Here is what I have done so far:

import pandas as pd
import numpy as np
import pymc3 as pm

df = pd.read_csv('dilution_data.csv')
y = df.concentration.values
x = df.dilution.values
with pm.Model() as model:

    beta = pm.HalfFlat('beta', shape = 4)
    alpha = pm.Uniform('alpha',0,1)
    sigma = pm.HalfFlat('sigma')

     g = beta[0] + beta[1]/(1+(x/beta[2])**beta[3])
    Y = pm.Normal('y',mu =g ,sd = (g/30)**(2*alpha)*sigma, observed = y)

    trace = pm.sample(2000, tune = 1000)

I am thrown the following error
MissingInputError: Input 0 of the graph (indices start from 0), used to compute Elemwise{exp,no_inplace}(beta_log__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.

A couple of questions:

  1. Have I set up the model correctly? Probably not because I am thrown an error.

  2. What is causing the error?



What is g in sd=(g / 30)**(2 * alpha) * sigma?


@junpenglao Sorry about that. He my update.


Hmm your code ran fine for me, although I am seeing a ValueError: Mass matrix contains zeros on the diagonal. error but that’s because of the HalfFlat prior.