title: PyMC error : hasattr(): attribute name must be string
body: <p>I'm having an issue running inference on a model in PyMC. I'm trying to run MCMC over a fairly complicated model, and I'm getting an error about </p>
  
  <pre><code>hasattr(): attribute name must be string
  </code></pre>
  
  <p>I get this on the final line of this block of code ( apologies, it's complicated, but I'm really not sure where the issue might be ).</p>
  
  <pre><code>import pymc
  from matplotlib import pyplot as plt
  import numpy as np
  
  # a is a temp variable
  # A is the data : a (2, 779)-shaped array of 0 and 1 only
  a = np.loadtxt("PLOM3/data/stoch.csv")
  A = np.zeros((2, len(a)-1))
  A[0, :] = a[:-1]
  A[1, :] = a[1:]
  
  num_cities = 2
  
  
  
  # Time
  t = range(len(A) - 1)
  
  # Noise term on p
  epsilon = pymc.Uniform("epsilon", 0, 1)
  
  # Exponential parameter
  gamma = 1. / A.mean(axis = 1)
  
  # Rate of imports
  lambda_ = pymc.Exponential("lambda_", gamma, size=num_cities)
  
  # Importations
  Y = [pymc.Poisson("Y", lambda_[i], size = A.shape[1]) for i in range(num_cities)]
  
  # Coefficients
  alpha = [pymc.Uniform("alpha", 0, 1) for i in range(num_cities)]
  beta = [pymc.Uniform("beta", 0, 1) for i in range(num_cities)]
  
  # Refactory Period
  delta = pymc.Exponential("delta", 0.2)
  
  # Delay
  d = pymc.Uniform("d", 0, 12, size = num_cities)
  
  # Time since last epidemic
  tau = np.zeros_like(A)
  tmp = np.where(A[i, :] == 1)[0]
  for i in range(2) :
      for j in range(len(tmp)-1) :
          tau[i, tmp[j]:tmp[j+1]] = tmp[j]
              tau[i, tmp[-1]:] = tmp[-1]
  
  # Bernoulli probabilities
  @pymc.deterministic
  def p(delta = delta, tau = tau, alpha = alpha, Y = Y, beta = beta, epsilon = epsilon, t = t) :
      out = np.zeros((2, 1))
      for i in range(2) :
          if t &gt; (tau[i, t] + delta) :
              out[i] = alpha[i] * Y[i] + beta[~1] * A[~1, t - d[i]] + epsilon
  
  # Time Series
  X = [pymc.Bernoulli("X", p, size = A.shape[1], value = A[i, :], observed = True) for i in range(num_cities)]
  
  
  
  model = pymc.Model([X, p, delta, alpha, beta, Y, lambda_, gamma, epsilon])
  mcmc = pymc.MCMC(model)
  </code></pre>
  
  <p>Any help would be really appreciated. There are few good tutorials out there on PyMC. I'm following Cameron Davidson-Pilon's excellent book, but so far, I can't find anything in there as to why this might give me this error.</p>
  
  <p>Thanks again.</p>
  
  <hr>
  
  <p>In response to Cam.Davidson.Pilon :</p>
  
  <p>The model describes measles in small populations. The important factor is that the size of the populations are smaller than the carrying capacity for measles, and so, instead of being endemic at all times, measles goes extinct after every epidemic. It is then reintroduced through immigration, and through country-level migration between cities in the country when an epidemic occurs there.</p>
  
  <p>The context is Iceland, 1900 - 1964 ( prevaccination ). We assume that measles can be imported through a Poisson process from overseas ( the Y variable ) with rates lambda, or from other cities in Iceland ( X ) with some delay ( d ). X is observed, sampled monthly, with a 1 if there was an epidemic that month and a 0 otherwise. </p>
  
  <p>We have X_i and Y_i for every city i. We assume that the values of X_i are Bernoulli-distributed with a probability of an epidemic p_i that is a function of the immigration into that particular city, with an importance alpha_i, and also a function of migration from other cities, should they have epidemics ( X_j, j =/= i ), with coefficient beta_ij, as well a background level of noise epsilon which represents uncertainty from where a case of measles may have come from. We also impose a refractory period delta, to allow susceptible individuals in a city to be born again.  </p>
  
  <p>Things I'm not certain about :  </p>
  
  <ul>
  <li>epsilon may not be necessary and / or a good thing</li>
  <li>I'd like to impose the constraint that alpha_i + sum_j beta_ij, i =/= j, be less than 1</li>
  <li>I'd like to have delta distributed more in an exponential form, but obviously discrete, as we only have monthly data</li>
  <li>Just spotted that d needs to be DiscreteUniform</li>
  <li>When I pass X_j into determining p_i, I may smooth it to allow for temporal jitter, probably just using a convolution with a Hanning window</li>
  </ul>
  
  <p>I think that about covers what's going on. Please let me know if anything is unclear ! Again, any input most welcome.</p>
  
  <p>Thanks again,</p>
  
  <p>Quentin</p>