Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100484

Re: Help on code comprehension from an example project of pymc

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Help on code comprehension from an example project of pymc
Date 2015-12-16 09:34 +1100
Message-ID <mailman.43.1450218867.22044.python-list@python.org> (permalink)
References <5e772de2-e50f-48f1-988c-a7c3eff33b10@googlegroups.com>

Show all headers | View raw


On Wed, Dec 16, 2015 at 3:15 AM, Robert <rxjwg98@gmail.com> wrote:
> When I review the code, I find 'data' in the original line:
>
> data = pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True)
>
> has not been referenced thereafter.
> If I comment out the line as:
>
> #data = pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True)
>
> the result is ugly different from the original.
>
> If I change it to:
>
> pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True)
>
> it still runs as the original.
>
> This is quite different from my any other language experience.
>
> Could you help me on this?

What this suggests is that the call you're doing returns something (as
every function call must, unless it raises an exception or doesn't
terminate), but it also has side effects. You're ignoring the return
value (which is why "data = " doesn't affect your code), but you need
the side effects. Unfortunately this is the case with quite a lot of
Python's high end math/stats modules, presumably because their APIs
are lifted directly from other languages; have a look at pyplot, for
instance, where a more Pythonic API would be to instantiate a plot
object every time. (In that particular example, I believe that's an
option; but most examples just use the module-level default.)

It's my guess (based on skimming the docs) that the objects passed in,
including those referenced as function default arguments, are getting
mutated. But I'm no expert on pymc. It's equally likely that
module-level (global) state is being changed.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help on code comprehension from an example project of pymc Robert <rxjwg98@gmail.com> - 2015-12-15 08:15 -0800
  Re: Help on code comprehension from an example project of pymc Chris Angelico <rosuav@gmail.com> - 2015-12-16 09:34 +1100
  Re: Help on code comprehension from an example project of pymc Terry Reedy <tjreedy@udel.edu> - 2015-12-15 17:45 -0500

csiph-web