title: Fitting logistic regression with PyMC: ZeroProbability error
body: <p>To teach myself PyMC I am trying to define a simple logistic regression. But I get a ZeroProbability error, and does not understand exactly why this happens or how to avoid it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import pymc
  import numpy as np
  
  x = np.array([85, 95, 70, 65, 70, 90, 75, 85, 80, 85])
  y = np.array([1., 1., 0., 0., 0., 1., 1., 0., 0., 1.])
  
  w0 = pymc.Normal('w0', 0, 0.000001)    # uninformative prior (any real number)
  w1 = pymc.Normal('w1', 0, 0.000001)    # uninformative prior (any real number)
  
  @pymc.deterministic
  def logistic(w0=w0, w1=w1, x=x):
      return 1.0 / (1. + np.exp(-(w0 + w1 * x)))
  
  observed = pymc.Bernoulli('observed', logistic, value=y, observed=True)
  </code></pre>
  
  <p>And here is the trace back with the error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "&lt;ipython-input-2-43ed68985dd1&gt;", line 24, in &lt;module&gt;
      observed = pymc.Bernoulli('observed', logistic, value=y, observed=True)
    File "/usr/local/lib/python2.7/site-packages/pymc/distributions.py", line 318, in __init__
      **arg_dict_out)
    File "/usr/local/lib/python2.7/site-packages/pymc/PyMCObjects.py", line 772, in __init__
      if not isinstance(self.logp, float):
    File "/usr/local/lib/python2.7/site-packages/pymc/PyMCObjects.py", line 929, in get_logp
      raise ZeroProbability(self.errmsg)
  ZeroProbability: Stochastic observed's value is outside its support,
   or it forbids its parents' current values.
  </code></pre>
  
  <p>I suspect <code>np.exp</code> to be causing the trouble, since it returns <code>inf</code> when the linear equation becomes too high.
  I know there are other ways to define a logistic regression using PyMC (<a href="http://nbviewer.ipython.org/gist/aflaxman/8329ec1b9f861469f896" rel="nofollow">her is one</a>), but I am interested in knowing why this approach does not work, and how I can define the regression using the <code>Bernoulli</code> object instead of using <code>bernoulli_like</code></p>