Using PyMC to find parameters in ode-based model

141 views
Skip to first unread message

gyro

unread,
Sep 3, 2009, 9:56:09 AM9/3/09
to PyMC
Hi,
I am a newbie when it comes to MCMC analysis and PyMC. I have been
able to carry out the analysis I will describe using another tool
(MCSim), but would really like to be able to use PyMC for this and
other analyses.

I am trying to fit an ordinary-differential-equation-based model to
find some unknown kinetic constants based on data. For illustration, I
have come up with a simpler model in which I generate 'data' using a
'forward' analysis using known kinetic constants.

I have posted the code to
http://python.pastebin.com/m287e13f9

When I run the analysis, I get an error almost immediately:
dc1dt = -k1*c1
TypeError: bad operand type for unary -: 'Normal'

I am not sure what to do to correct this error, nor if my code is
constructed properly to conduct this analysis.

I would really appreciate some help on this and some guidance if my
code is fundamentally flawed. I looked through the documentation and
PyMC website carefully, but was not able to extrapolate the examples
to my own application.

Thank you very much for any assistance you can provide.

Best Regards,
gyro

Anand Patil

unread,
Sep 3, 2009, 10:07:49 AM9/3/09
to py...@googlegroups.com
Hi Gyro,

I'm guessing this is a scope thing. Does
http://python.pastebin.com/pastebin.php?diff=f52a6f7a0 work?

Anand

gyro

unread,
Sep 3, 2009, 10:34:06 AM9/3/09
to PyMC
Hi Anand,
Thanks for the reply. Unfortunately, with that change I get the same
error.

It looks like PyMC is unable to apply the unary operator (-) to the
Normal type in the equation dc1dt = -k1*c1.
If I change that to dc1dt = -1.0*k*c1, I get the error
"TypeError: unsupported operand type(s) for *: 'float'"

Why is PyMC trying to do arithmetic operations on the Normal type and
not just on a (presumably floating point) sample drawn from the Normal
distribution? Any clarifications or hints are appreciated.

Thanks.

-gyro

On Sep 3, 8:07 am, Anand Patil <anand.prabhakar.pa...@gmail.com>
wrote:
> Hi Gyro,
>
> I'm guessing this is a scope thing. Doeshttp://python.pastebin.com/pastebin.php?diff=f52a6f7a0work?
>
> Anand
>

gyro

unread,
Sep 3, 2009, 10:36:38 AM9/3/09
to PyMC
Hi Anand,
Sorry, the full error got cut off in the latter case. The full error
is

TypeError: unsupported operand type(s) for *: 'float' and 'Normal'

Thanks.

-gyro

Anand Patil

unread,
Sep 3, 2009, 10:54:45 AM9/3/09
to py...@googlegroups.com
On Thu, Sep 3, 2009 at 3:34 PM, gyro<gyroma...@gmail.com> wrote:
>
> Hi Anand,
> Thanks for the reply. Unfortunately, with that change I get the same
> error.

Sorry about that. It looks like we've fixed whatever the problem was
since the 2.0 release, because with the svn/github head of the code I
don't see that error. I'm guessing the fix was revision 1190.

However, we introduced a new problem which the version on
http://python.pastebin.com/f57e19d3b avoids (I made a note of the
problem on the issues page). Does it work for you, with the updated
code?

Anand

gyro

unread,
Sep 3, 2009, 11:57:14 AM9/3/09
to PyMC
Hi Anand,
I downloaded the latest svn version of PyMC and used your modified
version of my code. Everything seems to run fine. Thanks!

Will updated binaries be posted at some point?

-gyro

On Sep 3, 8:54 am, Anand Patil >
> Sorry about that. It looks like we've fixed whatever the problem was
> since the 2.0 release, because with the svn/github head of the code I
> don't see that error. I'm guessing the fix was revision 1190.
>
> However, we introduced a new problem which the version onhttp://python.pastebin.com/f57e19d3bavoids (I made a note of the

Anand Patil

unread,
Sep 4, 2009, 4:26:04 AM9/4/09
to py...@googlegroups.com
On Thu, Sep 3, 2009 at 4:57 PM, gyro<gyroma...@gmail.com> wrote:
>
> Will updated binaries be posted at some point?

Eventually yes, probably concurrently with the 2.1 release. At the
moment we're focussing on getting the paper resubmitted but we'll keep
the mailing list posted on plans for the next release.

Anand

Reply all
Reply to author
Forward
0 new messages