0

I'm fairly new to python and pymc and wanted to try a problem out using pymc for learning purposes. I'm modeling a simple mendelian inheritence from grandparents down to son, but I don't understand how to reapply the same stochastic model multiple times. Any help is appreciated.

@py.stochastic
def childOf(value=1, d=0, m=0):
    pdra=d/2
    pmra=m/2

    # now return likelihood 
    if (value==0):
        return -np.log((1-pdra)*(1-pmra))
    elif (value==1):
        return -np.log((1-pdra)*(pmra)+(pdra)*(1-pmra))
    else:
        return -np.log((pdra*pmra))


p = [0.25,0.5,0.25]

gdd = py.Categorical("gdd", p, size=1) 
gdm = py.Categorical("gdm", p, size=1) 
gmd = py.Categorical("gmd", p, size=1) 
gmm = py.Categorical("gmm", p, size=1) 

gm=childOf('gm',d=gmm,m=gmd)
gd=childOf('gd',d=gdm,m=gdd)
gs=childOf('gs',d=gm,m=gd)

The error is a long string that ends with TypeError: 'numpy.ndarray' object is not callable on the first ChildOf

1 Answers1

0

You are not using your Stochastic object correctly. childOf is a PyMC object itself, and not a constructor of PyMC objects as you are attempting to do in the last three lines. A better approach would be to specify a log-probability function and use this as the logp attribute for each object. For example:

import pymc as pm
import numpy as np

def childOf_logp(value=1, d=0, m=0):
    pdra=d/2
    pmra=m/2

    # now return likelihood 
    if (value==0):
        return -np.log((1-pdra)*(1-pmra))
    elif (value==1):
        return -np.log((1-pdra)*(pmra)+(pdra)*(1-pmra))
    else:
        return -np.log((pdra*pmra))

@pm.stochastic
def childOf_pm(value=1, d=gmm,m=gmd):

    logp = childOf_logp
Chris Fonnesbeck
  • 4,143
  • 4
  • 29
  • 30