Skip to content

Commit

Permalink
Ran code_maintenance
Browse files Browse the repository at this point in the history
git-svn-id: https://pymc.googlecode.com/svn/trunk@1281 15d7aa0b-6f1a-0410-991a-d59f85d14984
  • Loading branch information
anand.prabhakar.patil committed May 6, 2009
1 parent 64dfb32 commit e2797a0
Show file tree
Hide file tree
Showing 34 changed files with 183 additions and 196 deletions.
2 changes: 1 addition & 1 deletion builddpkg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

python setupegg.py sdist_dsc --extra-cfg-file stdeb_all.cfg
cd deb_dist/pymc-2.0
dpkg-buildpackage -rfakeroot -uc -us
dpkg-buildpackage -rfakeroot -uc -us
20 changes: 10 additions & 10 deletions docs/INSTALL.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ \section{Dependencies}
Fortunately, there are currently only a few dependencies, and all are
freely available online.
\begin{itemize}
\item {}
\item {}
\href{http://www.python.org/.}{Python} version 2.5.

\item {}
\item {}
\href{http://www.scipy.org/NumPy}{NumPy} (1.2 or newer): The fundamental scientific programming package, it provides a
multidimensional array type and many useful functions for numerical analysis.

\item {}
\item {}
\href{http://matplotlib.sourceforge.net/}{Matplotlib} (optional): 2D plotting library which produces publication
quality figures in a variety of image formats and interactive environments

\item {}
\item {}
\href{http://www.pytables.org/moin}{pyTables} (optional): Package for managing hierarchical datasets and
designed to efficiently and easily cope with extremely large amounts of data.
Requires the \href{http://www.hdfgroup.org/HDF5/}{HDF5} library.

\item {}
\item {}
\href{http://code.google.com/p/pydot/}{pydot} (optional): Python interface to Graphviz's Dot language, it allows
PyMC to create both directed and non-directed graphical representations of models.
Requires the \href{http://www.graphviz.org/}{Graphviz} library.

\item {}
\item {}
\href{http://www.scipy.org/}{SciPy} (optional): Library of algorithms for mathematics, science
and engineering.

\item {}
\item {}
\href{http://ipython.scipy.org/}{IPython} (optional): An enhanced interactive Python shell and an
architecture for interactive parallel computing.

\item {}
\item {}
\href{http://somethingaboutorange.com/mrl/projects/nose/}{nose} (optional): A test discovery-based unittest extension (required
to run the test suite).

Expand Down Expand Up @@ -99,10 +99,10 @@ \section{Installing from pre-built binaries}
\usecounter{listcnt0}
\setlength{\rightmargin}{\leftmargin}
}
\item {}
\item {}
Download the installer for your platform from \href{http://pypi.python.org/pypi/pymc/}{PyPI}.

\item {}
\item {}
Double-click the executable installation package, then follow the
on-screen instructions.

Expand Down
28 changes: 14 additions & 14 deletions docs/README.tex
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ \section{Purpose}
\section{Features}
\label{features}
\begin{itemize}
\item {}
\item {}
Fits Bayesian statistical models you create with Markov chain Monte Carlo and
other algorithms.

\item {}
\item {}
Large suite of well-documented statistical distributions.

\item {}
\item {}
Gaussian processes.

\item {}
\item {}
Sampling loops can be paused and tuned manually, or saved and restarted later.

\item {}
\item {}
Creates summaries including tables and plots.

\item {}
\item {}
Traces can be saved to the disk as plain text, Python pickles, SQLite or MySQL
database, or hdf5 archives.

\item {}
\item {}
Convergence diagnostics.

\item {}
\item {}
Extensible: easily incorporates custom step methods and unusual probability
distributions.

\item {}
\item {}
MCMC loops can be embedded in larger programs, and results can be analyzed
with the full power of Python.

Expand All @@ -63,20 +63,20 @@ \section{Features}
\section{What's new in 2.0}
\label{what-s-new-in-2-0}
\begin{itemize}
\item {}
\item {}
New flexible object model and syntax (not backward-compatible).

\item {}
\item {}
Reduced redundant computations: only relevant log-probability terms are
computed, and these are cached.

\item {}
\item {}
Optimized probability distributions.

\item {}
\item {}
New adaptive blocked Metropolis step method.

\item {}
\item {}
Much more!

\end{itemize}
Expand Down
20 changes: 10 additions & 10 deletions docs/database.tex
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,22 @@ \subsection{mysql}
port of the host server is given, along with a valid user name and password.
These parameters are passed when the \texttt{Sampler} is instantiated:
\begin{itemize}
\item {}
\item {}
\texttt{dbname} (\titlereference{string}) The name of the database file.

\item {}
\item {}
\texttt{dbuser} (\titlereference{string}) The database user name.

\item {}
\item {}
\texttt{dbpass} (\titlereference{string}) The user password for this database.

\item {}
\item {}
\texttt{dbhost} (\titlereference{string}) The location of the database host.

\item {}
\item {}
\texttt{dbport} (\titlereference{int}) The port number to use to reach the database host.

\item {}
\item {}
\texttt{dbmode} {\{}\texttt{a}, \texttt{w}{\}} File mode. Use \texttt{a} to append values, and \texttt{w}
to overwrite an existing database.

Expand Down Expand Up @@ -311,17 +311,17 @@ \subsection{hdf5}

The \texttt{hdf5} Database takes the following parameters:
\begin{itemize}
\item {}
\item {}
\texttt{dbname} (\titlereference{string}) Name of the hdf5 file.

\item {}
\item {}
\texttt{dbmode} {\{}\texttt{a}, \texttt{w}, \texttt{r}{\}} File mode: \texttt{a}: append, \texttt{w}: overwrite,
\texttt{r}: read-only.

\item {}
\item {}
\texttt{dbcomplevel} : (\titlereference{int} (0-9)) Compression level, 0: no compression.

\item {}
\item {}
\texttt{dbcomplib} (\titlereference{string}) Compression library (\texttt{zlib}, \texttt{bzip2}, \texttt{lzo})

\end{itemize}
Expand Down
2 changes: 1 addition & 1 deletion docs/extending.tex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ \subsection{General step methods} \label{user-gen}
\begin{description}
\item[\code{_id}:] A string that can identify each step method uniquely (usually something like \code{<class_name>_<stochastic_name>}).
\item[\code{adaptive_scale_factor}:] An `adaptive scale factor'. This attribute is only needed if the default \code{tune()} method is used.
\item[\code{_tuning_info}:] A list of strings giving the names of any tuning parameters. For \texttt{Metropolis} instances, this would be \texttt{adaptive_scale_factor}. This list is used to keep traces of tuning parameters in order to verify `diminishing tuning' \cite{tuning}.
\item[\code{_tuning_info}:] A list of strings giving the names of any tuning parameters. For \texttt{Metropolis} instances, this would be \texttt{adaptive_scale_factor}. This list is used to keep traces of tuning parameters in order to verify `diminishing tuning' \cite{tuning}.
\end{description}

All step methods have a property called \code{loglike}, which returns the sum of the log-probabilities of the union of the extended children of \code{self.stochastics}. This quantity is one term in the log of the Metropolis-Hastings acceptance ratio.
Expand Down
4 changes: 2 additions & 2 deletions docs/modelfitting.tex
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ \section{Normal approximations} \label{sec:norm-approx}

\code{MCMC} provides the following useful methods:
\begin{description}
\item[\code{sample(iter, burn=0, thin=1, tune\_interval=1000, tune\_throughout=True, save\_interval=None, verbose=0)}:] Runs the MCMC algorithm and produces the traces. The \code{iter} argument controls the total number of MCMC iterations. No tallying will be done during the first \code{burn} iterations; these samples will be forgotten. After this burn-in period, tallying will be done each \code{thin} iterations. Tuning will be done each \code{tune\_interval} iterations. If \code{tune\_throughout=False}, no more tuning will be done after the burnin period. The model state will be saved every \code{save\_interval} iterations, if given.
\item[\code{sample(iter, burn=0, thin=1, tune\_interval=1000, tune\_throughout=True, save\_interval=None, verbose=0)}:] Runs the MCMC algorithm and produces the traces. The \code{iter} argument controls the total number of MCMC iterations. No tallying will be done during the first \code{burn} iterations; these samples will be forgotten. After this burn-in period, tallying will be done each \code{thin} iterations. Tuning will be done each \code{tune\_interval} iterations. If \code{tune\_throughout=False}, no more tuning will be done after the burnin period. The model state will be saved every \code{save\_interval} iterations, if given.
\item[\code{isample(iter, burn=0, thin=1, tune\_interval=1000, tune\_throughout=True, save\_interval=None, verbose=0)}:] An interactive version of \code{sample}. The sampling loop may be paused at any time, returning control to the user.
\item[\code{use_step_method(method, *args, **kwargs)}:] Creates an instance of step method class \code{method} to handle some stochastic variables. The extra arguments are passed to the \code{init} method of \code{method}. Assigning a step method to a variable manually will prevent the \code{MCMC} instance from automatically assigning one. However, you may handle a variable with multiple step methods.
% \item[\code{assign_step_methods()}:] Assigns step methods to all stochastic variables that do not currently have any. This method is called whenever \code{sample} or \code{isample} is called, but it can be useful to call it directly to see what the default step methods will be.
Expand Down Expand Up @@ -206,7 +206,7 @@ \subsection{Metropolis step methods} \label{metropolis}
\item[\code{verbose}:] An integer.
\end{description}

Metropolis step methods adjust their initial proposal standard deviations using an attribute called \code{adaptive_scale_factor}. When \code{tune()} is called, the acceptance ratio of the step method is examined and this scale factor is updated accordingly. If the proposal distribution is normal, proposals will have standard deviation \code{self.proposal\_sd * self.adaptive_scale_factor}.
Metropolis step methods adjust their initial proposal standard deviations using an attribute called \code{adaptive_scale_factor}. When \code{tune()} is called, the acceptance ratio of the step method is examined and this scale factor is updated accordingly. If the proposal distribution is normal, proposals will have standard deviation \code{self.proposal\_sd * self.adaptive_scale_factor}.

By default, tuning will continue throughout the sampling loop, even after the burnin period is over. This can be changed via the \texttt{tune\_throughout} argument to \texttt{MCMC.sample}. If an adaptive step method's \texttt{tally} flag is set (the default for \texttt{Metropolis}), a trace of its tuning parameters will be kept. If you allow tuning to continue throughout the sampling loop, it is important to verify that the `Diminishing Tuning' condition of \cite{tuning} is satisfied: the amount of tuning should decrease to zero, or tuning should become very infrequent.

Expand Down
18 changes: 9 additions & 9 deletions pymc/CircularStochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@
class CircularStochastic(Stochastic):
"""
C = CircularStochastic(lo, hi, *args, **kwargs)
Takes two special parents, lo and hi; any incoming value
will be mapped into the interval [lo,hi).
args and kwargs will be passed to Stochastic.__init__.
:SeeAlso: Stochastic
"""
def __init__(self, lo, hi, *args, **kwargs):
self.interval_parents = Container([hi, lo])
Stochastic.__init__(self, *args, **kwargs)

def set_value(self, value):
modded_value = mod_to_circle(value, *self.interval_parents.value).reshape(np.shape(value))
Stochastic.set_value(self, modded_value)
value = property(Stochastic.get_value, set_value)

class CircVonMises(CircularStochastic):
"""
V = CircVonMises(name, mu, kappa, value=None, observed=False, size=1, trace=True, rseed=True, doc=None, verbose=0)
Stochastic variable with Von Mises distribution.
Parents are: mu, kappa.
Docstring of log-probability function:
"""+von_mises_like.__doc__
def __init__( self,
name,
mu, kappa,
value=None,
observed=False,
size=1,
size=1,
trace=True,
cache_depth=2,
rseed=True,
plot=None,
verbose = 0):

if value is None:
arg_eval = Container([mu, kappa]).value
value = rvon_mises(arg_eval[0], arg_eval[1], size=size)

parents = {'mu':mu, 'kappa':kappa}
logp = valuewrapper(von_mises_like)
random = lambda mu, kappa, size=size: rvon_mises(mu, kappa, size=size)
Expand Down
4 changes: 2 additions & 2 deletions pymc/CommonDeterministics.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def wrapper(**kwargs):
%s
"""%(func.__name__, '_'*60, func.__doc__)
return dtrm_generator


def pfunc(func):
"""
Expand Down Expand Up @@ -468,7 +468,7 @@ def pfunc(func):
raise cls, inst, tb
fargs, fvarargs, fvarkw, fdefaults = inspect.getargspec(func)
n_fargs = len(fargs)

def dtrm_generator(*args, **kwds):
name = func.__name__ + '('+'_'.join([str(arg) for arg in list(args) + kwds.values()])+')'
doc_str = 'A deterministic returning %s(%s, %s)'%(func.__name__, ', '.join([str(arg) for arg in args]), ', '.join(['%s=%s'%(key, str(val)) for key, val in kwds.iteritems()]))
Expand Down
4 changes: 2 additions & 2 deletions pymc/Container_values.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cdef class LCValue:
cdef int n_val, n_nonval

def __init__(self, container):

cdef int i
self._value = container._value
self.val_ind = <int*> PyArray_DATA(container.val_ind)
Expand All @@ -27,7 +27,7 @@ cdef class LCValue:
self.nonval_ind = <int*> PyArray_DATA(container.nonval_ind)
self.nonval_obj = <void**> PyArray_DATA(container.nonval_obj)
self.n_nonval = container.n_nonval

def run(self):
cdef int i
for i from 0 <= i < self.n_val:
Expand Down
14 changes: 7 additions & 7 deletions pymc/MCMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, input=None, db='ram', name='MCMC', calc_deviance=True, **kwds
Keywords arguments to be passed to the database instantiation method.
"""
Sampler.__init__(self, input, db, name, calc_deviance=calc_deviance, **kwds)

self._sm_assigned = False
self.step_method_dict = {}
for s in self.stochastics:
Expand Down Expand Up @@ -100,7 +100,7 @@ def assign_step_methods(self):
Make sure every stochastic variable has a step method. If not,
assign a step method from the registry.
"""

if not self._sm_assigned:

# Assign dataless stepper first
Expand Down Expand Up @@ -132,7 +132,7 @@ def assign_step_methods(self):
self.step_methods = set()
for s in self.stochastics:
self.step_methods |= set(self.step_method_dict[s])

for sm in self.step_methods:
if sm.tally:
for name in sm._tuning_info:
Expand All @@ -146,7 +146,7 @@ def sample(self, iter, burn=0, thin=1, tune_interval=1000, tune_throughout=True,
sample(iter, burn, thin, tune_interval, tune_throughout, save_interval, verbose)
Initialize traces, run sampling loop, clean up afterward. Calls _loop.
:Parameters:
- iter : int
Total number of iterations to do
Expand All @@ -157,7 +157,7 @@ def sample(self, iter, burn=0, thin=1, tune_interval=1000, tune_throughout=True,
- tune_interval : int
Step methods will be tuned at intervals of this many iterations, default 1000
- tune_throughout : boolean
If true, tuning will continue after the burnin period (True); otherwise tuning
If true, tuning will continue after the burnin period (True); otherwise tuning
will halt at the end of the burnin period.
- save_interval : int or None
If given, the model state will be saved at intervals of this many iterations
Expand Down Expand Up @@ -201,8 +201,8 @@ def _loop(self):
# Tune at interval
if i and not (i % self._tune_interval) and self._tuning:
self.tune()
if i == self._burn:

if i == self._burn:
if self.verbose>0:
print 'Burn-in interval complete'
if not self._tune_throughout:
Expand Down
2 changes: 1 addition & 1 deletion pymc/Matplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def zplot(pvalue_dict, name='', format='png', path='./', fontmap = {1:10, 2:8, 3
vname = var
vname += " (%i)" % size(zvals)
labels = append(labels, vname)

# Spawn new figure
figure()
subplot(111)
Expand Down
4 changes: 2 additions & 2 deletions pymc/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _assign_database_backend(self, db):

# Assign Trace instances to tallyable objects.
self.db.connect_model(self)


def pause(self):
"""Pause the sampler. Sampling can be resumed by calling `icontinue`.
Expand Down Expand Up @@ -619,7 +619,7 @@ def trace(self, name, chain=-1):
return self.db.trace(name.__name__, chain)
else:
raise ValueError, 'Name argument must be string or Variable, got %s.'%name

def _get_deviance(self):
return self._sum_deviance()
deviance = property(_get_deviance)
Expand Down
Loading

0 comments on commit e2797a0

Please sign in to comment.