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


Groups > comp.lang.python > #100401

Re: Help on class understanding in pymc code

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Help on class understanding in pymc code
Date Mon, 14 Dec 2015 02:09:51 +0100
Organization None
Lines 202
Message-ID <mailman.0.1450055409.14916.python-list@python.org> (permalink)
References <8914575b-92c4-4b0e-adbf-ccb63c5edde5@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de 6RxqWaf9cnErddbivZQv7AxKOyFK2Y/ariSGORAwUQwA==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '---------': 0.05; 'elements.': 0.05; 'initialize': 0.05; 'skip:p 60': 0.05; 'attributes': 0.07; 'constructor': 0.07; 'line:': 0.07; 'skip:/ 10': 0.07; 'skip:\\ 10': 0.07; 'subject:code': 0.07; 'variable,': 0.07; "'no": 0.09; 'considered.': 0.09; 'definition,': 0.09; 'inherited': 0.09; 'instance.': 0.09; 'item,': 0.09; 'key)': 0.09; 'keyed': 0.09; 'mentions': 0.09; 'models.': 0.09; 'otherwise)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'appropriate': 0.14; 'value.': 0.15; 'variables': 0.15; '(data': 0.16; 'attributes:': 0.16; 'conditional': 0.16; 'container,': 0.16; 'containers': 0.16; 'descriptors': 0.16; 'dictionary,': 0.16; 'docstring': 0.16; 'fits': 0.16; 'inheritance': 0.16; 'name=none,': 0.16; 'namespace.': 0.16; 'naming': 0.16; 'nodes': 0.16; 'parameter:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'set,': 0.16; 'skip:[ 50': 0.16; 'subclasses.': 0.16; 'subject:class': 0.16; 'tuple,': 0.16; 'variable.': 0.16; 'weight,': 0.16; 'wrote:': 0.16; 'element': 0.18; 'module,': 0.18; 'input': 0.18; 'variable': 0.18; '>>>': 0.20; 'class,': 0.22; 'variables.': 0.22; 'defined': 0.23; 'fit': 0.23; 'references': 0.23; 'sets': 0.23; 'import': 0.24; 'url:edu': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'rest': 0.26; 'skip:m 30': 0.27; 'object,': 0.27; 'values': 0.28; 'initial': 0.28; 'resolution': 0.28; 'dictionary': 0.29; 'factor': 0.29; 'initialized': 0.29; 'node': 0.29; 'seed': 0.29; 'subject:skip:u 10': 0.29; 'weak': 0.29; 'objects': 0.29; 'random': 0.29; 'code': 0.30; 'class.': 0.30; 'skip:s 30': 0.31; 'skip:_ 10': 0.32; 'says': 0.32; 'useful': 0.33; 'class': 0.33; 'values.': 0.33; "skip:' 20": 0.34; 'previous': 0.34; 'skip:d 20': 0.34; 'list': 0.34; 'so,': 0.35; 'exist': 0.35; 'false': 0.35; 'instance': 0.35; 'nothing.': 0.35; 'replaced': 0.35; 'robert': 0.35; 'skip:p 30': 0.35; 'step': 0.36; 'but': 0.36; 'list,': 0.36; 'there': 0.36; 'created': 0.36; 'assigned': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; '(with': 0.38; 'detail': 0.38; 'skip:p 20': 0.38; 'hi,': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'called': 0.40; 'skip:u 10': 0.61; 'skip:n 10': 0.62; 'complete': 0.63; 'here:': 0.63; 'between': 0.65; 'therefore': 0.67; 'link:': 0.69; 'status:': 0.72; 'order:': 0.84; 'potentials': 0.84; 'stochastic': 0.84; 'monte': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8403.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100401

Show key headers only | View raw


Robert wrote:

> Hi,
> 
> I follow code example at link:
> 
> https://users.obs.carnegiescience.edu/cburns/ipynbs/PyMC.html
> 
> 
> There is the following code line:
> 
> sampler = pymc.MCMC([alpha,betax,betay,eps,model,tau,z_obs,x_true,y_true])
> 
> 
> I want to know the detail of pymc.MCMC, then I get help content of it
> with:
> 
> /////////////
> help(pymc.MCMC)
> Help on class MCMC in module pymc.MCMC:
> 
> class MCMC(pymc.Model.Sampler)
>  |  This class fits probability models using Markov Chain Monte Carlo.
>  |  Each stochastic variable is assigned a StepMethod object, which makes
>  |  it take a single MCMC step conditional on the rest of the model. These
>  |  step methods are called in turn.
>  |  
>  |    >>> A = MCMC(input, db, verbose=0)
>  |  
> \\\\\\\\\\\\\\\\\\
> 
> 
> help('pymc.Model.Sampler')
> no Python documentation found for 'pymc.Model.Sampler'
> 
> 
> help('pymc.Model')
> Help on class Model in pymc:
> 
> pymc.Model = class Model(pymc.Container.ObjectContainer)
>  |  The base class for all objects that fit probability models. Model is
>  |  initialized with:
>  |  
>  |    >>> A = Model(input, verbose=0)
>  |  
>  |    :Parameters:
>  |      - input : module, list, tuple, dictionary, set, object or nothing.
>  |          Model definition, in terms of Stochastics, Deterministics,
>  |          Potentials and Containers. If nothing, all nodes are collected
>  |          from the base namespace.
>  |  
>  |  Attributes:
>  |    - deterministics
>  |    - stochastics (with observed=False)
>  |    - data (stochastic variables with observed=True)
>  |    - variables
>  |    - potentials
>  |    - containers
>  |    - nodes
>  |    - all_objects
>  |    - status: Not useful for the Model base class, but may be used by
>  |    subclasses.
>  |  
>  |  The following attributes only exist after the appropriate method is
>  |  called:
>  |    - moral_neighbors: The edges of the moralized graph. A dictionary,
>  |    keyed by stochastic variable,
>  |      whose values are sets of stochastic variables. Edges exist between
>  |      the key variable and all variables in the value. Created by method
>  |      _moralize.
>  |    - extended_children: The extended children of self's stochastic
>  |    variables. See the docstring of
>  |      extend_children. This is a dictionary keyed by stochastic
>  |      variable.
>  |    - generations: A list of sets of stochastic variables. The members
>  |    of each element only have parents in
>  |      previous elements. Created by method find_generations.
>  |  
>  |  Methods:
>  |     - sample_model_likelihood(iter): Generate and return iter samples
>  |     of p(data and potentials|model).
>  |       Can be used to generate Bayes' factors.
>  |  
>  |  :SeeAlso: Sampler, MAP, NormalApproximation, weight, Container, graph.
>  |  
>  |  Method resolution order:
>  |      Model
>  |      pymc.Container.ObjectContainer
>  |      pymc.six.NewBase
>  |      pymc.Node.ContainerBase
>  |      __builtin__.object
>  |  
>  |  Methods defined here:
>  |  
>  |  __init__(self, input=None, name=None, verbose=-1)
>  |      Initialize a Model instance.
>  |      
>  |      :Parameters:
>  |        - input : module, list, tuple, dictionary, set, object or
>  |        nothing.
>  |            Model definition, in terms of Stochastics, Deterministics,
>  |            Potentials and Containers. If nothing, all nodes are
>  |            collected from the base namespace.
>  |  
>  |  draw_from_prior(self)
>  |      Sets all variables to random values drawn from joint 'prior',
>  |      meaning contributions of data and potentials to the joint
>  |      distribution are not considered.
>  |  
>  |  get_node(self, node_name)
>  |      Retrieve node with passed name
>  |  
>  |  seed(self)
>  |      Seed new initial values for the stochastics.
>  |  
>  |  ----------------------------------------------------------------------
>  |  Data descriptors defined here:
>  |  
>  |  generations
>  |  
>  |  ----------------------------------------------------------------------
>  |  Data and other attributes defined here:
>  |  
>  |  __slotnames__ = []
>  |  
>  |  register = False
>  |  
>  |  ----------------------------------------------------------------------
>  |  Methods inherited from pymc.Container.ObjectContainer:
>  |  
>  |  replace(self, item, new_container, key)
>  |  
>  |  ----------------------------------------------------------------------
>  |  Data descriptors inherited from pymc.Container.ObjectContainer:
>  |  
>  |  value
>  |      A copy of self, with all variables replaced by their values.
>  |  
>  |  ----------------------------------------------------------------------
>  |  Methods inherited from pymc.Node.ContainerBase:
>  |  
>  |  assimilate(self, new_container)
>  |  
>  |  ----------------------------------------------------------------------
>  |  Data descriptors inherited from pymc.Node.ContainerBase:
>  |  
>  |  __dict__
>  |      dictionary for instance variables (if defined)
>  |  
>  |  __weakref__
>  |      list of weak references to the object (if defined)
>  |  
>  |  logp
>  |      The summed log-probability of all stochastic variables (data
>  |      or otherwise) and factor potentials in self.
>  |  
>  |  ----------------------------------------------------------------------
>  |  Data and other attributes inherited from pymc.Node.ContainerBase:
>  |  
>  |  change_methods = []
>  |  
>  |  containing_classes = []
> ---------
> 
> 
> Now, I have puzzles on the class constructor input parameter:
> [alpha,betax,betay,eps,model,tau,z_obs,x_true,y_true]
> 
> 1. 'class MCMC(pymc.Model.Sampler)' says its inheritance is from
> 'pymc.Model.Sampler'
> 
> 2. When I try to get help on 'pymc.Model.Sampler', it says:
>    'no Python documentation found for 'pymc.Model.Sampler'
> 
> 3. When I continue to catch help on 'pymc.Model.Sampler', I don't see
> content mentions 'Sampler'. This complete help message is shown above.
> 
> So, what is 'pymc.Model.Sampler'?

Unfortunately there is a module pymc.Model and a class pymc.Model.Model, and 
in pymc.__init__.py there is code that overwrites the module with the class. 
Therefore when you write

pymc.Model

you get

pymc.Model.Model

as you can see when you type

>>> import pymc
>>> pymc.Model
<class 'pymc.Model.Model'>

To get around this bad naming use

>>> from pymc.Model import Sampler
>>> help(Sampler)


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


Thread

Help on class understanding in pymc code Robert <rxjwg98@gmail.com> - 2015-12-13 16:40 -0800
  Re: Help on class understanding in pymc code Peter Otten <__peter__@web.de> - 2015-12-14 02:09 +0100
    Re: Help on class understanding in pymc code Robert <rxjwg98@gmail.com> - 2015-12-13 17:45 -0800
      Re: Help on class understanding in pymc code Peter Otten <__peter__@web.de> - 2015-12-14 09:56 +0100

csiph-web