Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Converting WinBUGS model
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Saeed Siam  
View profile  
 More options Jun 20 2010, 6:27 pm
From: Saeed Siam <saeed.s...@gmail.com>
Date: Sun, 20 Jun 2010 15:27:25 -0700 (PDT)
Local: Sun, Jun 20 2010 6:27 pm
Subject: Converting WinBUGS model
Hi,

I am new to PyMC. For starting, I was trying to convert WinBUGS <a
href="http://users.aims.ac.za/~mackay/BUGS/Examples/Eyes.html"> Eyes
example </a> to PyMC.

I have assumed that Categorical() in the PyMC is equivalent the
WinBUGS' dcat(), So for the following WinBUGS model,

   model
   {
      for( i in 1 : N ) {
         y[i] ~ dnorm(mu[i], tau)
         mu[i] <- lambda[T[i]]
         T[i] ~ dcat(P[])
      }
      P[1:2] ~ ddirch(alpha[])
      theta ~ dnorm(0.0, 1.0E-6)I(0.0, )
      lambda[2] <- lambda[1] + theta
      lambda[1] ~ dnorm(0.0, 1.0E-6)
      tau ~ dgamma(0.001, 0.001) sigma <- 1 / sqrt(tau)
   }

I have done similar to <a href="http://pastebin.com/GXwLs5bC">this </
a>. But it raises pymc.Node.ZeroProbability exception with the
message  "Stochastic T_1's value is outside its support,
 or it forbids its parents' current values."

I would really appreciate if you can point out what I am doing wrong.

regards,
Saeed


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Salvatier  
View profile   Translate to Translated (View Original)
 More options Jun 21 2010, 3:08 am
From: John Salvatier <jsalv...@u.washington.edu>
Date: Mon, 21 Jun 2010 00:08:53 -0700
Local: Mon, Jun 21 2010 3:08 am
Subject: Re: [pymc] Converting WinBUGS model

I have not gone through all your code yet, but the main difference between
how you would code a BUGS model and a PyMC model relevent to your model is
that in PyMC is that you should vectorize your model. Instead of looping
through your variables, you should create arrays of variables and give those
as arguments to other parts of your model.

For example, instead of your second loop, you should do something like:

    T = pymc.Categorical('T', p=p1,p2)
    mu = pymc.Deterministic(eval=lambda t=T,lambda_0=lambdas[0],
lambda_1=lambdas[1]: t < 0.5 & lambda_0 | lambda_1,
            name='mu')

    Y = pymc.Binomial('Y', n=mu, p=tau, value=y_data, observed=True)

(note that numpy arrays sadly do not work with the 'and' and 'or' operators.
You must use & and | or use the functions.
PyMC *should* be able to deal with how you have written you model, but it is
not how PyMC is meant to be used so it will be harder to debug your model.
PyMC should also normally be able to deal with natural expressions of your
variables to create deterministics, but I am not certain whether this works
with the & and | operators. For example, you might try,

mu = T < .5 & (lambdas[0]  |  lambdas[1])

However, I am not 100% certain that will work (some of the operators might
not be implemented).

I also notice you have the expression "tau**(-1/2)" in your program.
Unfortunately Python does integer division for 1/2 so this will evaluate as
-1 (this will be fixed soon), so use tau**(-.5)  or just sigma = tau **-.5.

I am not certain what your specific error is due to.

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Salvatier  
View profile  
 More options Jun 21 2010, 3:15 am
From: John Salvatier <jsalv...@u.washington.edu>
Date: Mon, 21 Jun 2010 00:15:56 -0700
Local: Mon, Jun 21 2010 3:15 am
Subject: Re: [pymc] Converting WinBUGS model

That particular error means that the value of parameters of T are invalid
for a Categorical distribution. "parents" refers to the parameters of the
distribution or deterministic. Can you look at prior.value[0] and
prior.value[1]?

John

On Mon, Jun 21, 2010 at 12:08 AM, John Salvatier
<jsalv...@u.washington.edu>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »