Skip to content

Commit bbb92bd

Browse files
committed
0.10.1
1 parent 89e39b9 commit bbb92bd

File tree

9 files changed

+143
-16
lines changed

9 files changed

+143
-16
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,25 @@ Which compiles to something as shown below:
4848

4949
-----------
5050

51+
### Installation
5152

5253
Install via `pip`:
5354

5455
pip install chainconsumer
5556

5657

58+
----------
59+
60+
## Contributing
61+
62+
Users that wish to contribute to this project may do so in a number of ways.
63+
Firstly, for any feature requests, bugs or general ideas, please raise an issue
64+
via [Github](https://github.com/samreay/ChainConsumer/issues).
65+
66+
If you wish to contribute code to the project, please simple fork the project on
67+
Github and then raise a pull request. Pull requests will be reviewed to determine
68+
whether the changes are major or minor in nature, and to ensure all changes are tested.
69+
5770
----------
5871

5972
Please feel free to fork the project and open pull-requests, or

chainconsumer/chain.py

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ChainConsumer(object):
1414
""" A class for consuming chains produced by an MCMC walk
1515
1616
"""
17-
__version__ = "0.10.0"
17+
__version__ = "0.10.1"
1818

1919
def __init__(self):
2020
logging.basicConfig()
@@ -44,12 +44,14 @@ def add_chain(self, chain, parameters=None, name=None, weights=None, posterior=N
4444
----------
4545
chain : str|ndarray|dict
4646
The chain to load. Normally a ``numpy.ndarray``. If a string is found, it
47-
interprets the string as a filename and attempts to load it in. If a ``dict``
48-
is passed in, it assumes the dict has keys of parameter names and values of
49-
an array of samples. Notice that using a dictionary puts the order of
50-
parameters in the output under the control of the python ``dict.keys()`` function.
47+
interprets the string as a filename and attempts to load it in. If a ``dict``
48+
is passed in, it assumes the dict has keys of parameter names and values of
49+
an array of samples. Notice that using a dictionary puts the order of
50+
parameters in the output under the control of the python ``dict.keys()`` function.
5151
parameters : list[str], optional
52-
A list of parameter names, one for each column (dimension) in the chain.
52+
A list of parameter names, one for each column (dimension) in the chain. This parameter
53+
should remain ``None`` if a dictionary is given as ``chain``, as the parameter names
54+
are taken from the dictionary keys.
5355
name : str, optional
5456
The name of the chain. Used when plotting multiple chains at once.
5557
weights : ndarray, optional
@@ -164,6 +166,12 @@ def configure_general(self, bins=None, flip=True, rainbow=None, colours=None,
164166
How much to smooth the marginalised distributions using a gaussian filter.
165167
If ``kde`` is set to true, this parameter is ignored. Setting it to either
166168
``0``, ``False`` or ``None`` disables smoothing.
169+
170+
171+
Returns
172+
-------
173+
ChainConsumer
174+
Itself, to allow chaining calls.
167175
"""
168176
assert rainbow is None or colours is None, \
169177
"You cannot both ask for rainbow colours and then give explicit colours"
@@ -233,6 +241,11 @@ def configure_contour(self, sigmas=None, cloud=None, shade=None,
233241
shade_alpha : float|list[float], optional
234242
Filled contour alpha value override. Default is 1.0. If a list is passed, you can set the
235243
shade opacity for specific chains.
244+
245+
Returns
246+
-------
247+
ChainConsumer
248+
Itself, to allow chaining calls.
236249
"""
237250
num_chains = len(self.chains)
238251

@@ -276,13 +289,20 @@ def configure_bar(self, summary=None, shade=None): # pragma: no cover
276289
chain consumer, as the consume changes configuration values depending on
277290
the supplied data.
278291
292+
Parameters
293+
----------
279294
summary : bool, optional
280295
If overridden, sets whether parameter summaries should be set as axis titles.
281296
Will not work if you have multiple chains
282297
shade : bool|list[bool], optional
283298
If set to true, shades in confidence regions in under histogram. By default
284299
this happens if you less than 3 chains, but is disabled if you are comparing
285300
more chains. You can pass a list if you wish to shade some chains but not others.
301+
302+
Returns
303+
-------
304+
ChainConsumer
305+
Itself, to allow chaining calls.
286306
"""
287307
if summary is not None:
288308
summary = summary and len(self.chains) == 1
@@ -306,6 +326,16 @@ def configure_truth(self, **kwargs): # pragma: no cover
306326
if you want some basic control.
307327
308328
Default is to use an opaque black dashed line.
329+
330+
Parameters
331+
----------
332+
kwargs : dict
333+
The keyword arguments to unwrap when calling ``axvline`` and ``axhline``.
334+
335+
Returns
336+
-------
337+
ChainConsumer
338+
Itself, to allow chaining calls.
309339
"""
310340
if kwargs.get("ls") is None and kwargs.get("linestyle") is None:
311341
kwargs["ls"] = "--"
@@ -449,6 +479,11 @@ def get_parameter_text(self, lower, maximum, upper, wrap=False):
449479
The upper bound on the parameter
450480
wrap : bool
451481
Wrap output text in dollar signs for LaTeX
482+
483+
Returns
484+
-------
485+
str
486+
The formatted text given the parameter bounds
452487
"""
453488
if lower is None or upper is None:
454489
return ""
@@ -488,7 +523,30 @@ def get_parameter_text(self, lower, maximum, upper, wrap=False):
488523
text = "$%s$" % text
489524
return text
490525

491-
def divide_chain(self, i, num_walkers):
526+
def divide_chain(self, num_walkers, i=0):
527+
"""
528+
Returns a ChainConsumer instance containing ``num_walker`` chains,
529+
each formed by splitting the ``i``th chain ``num_walker`` times.
530+
531+
This method might be useful if, for example, your chain was made using
532+
MCMC with 4 walkers. To check the sampling of all 4 walkers agree, you could
533+
call this with ``num_walkers=4`` and plot, and hopefully all four contours
534+
you would see all agree.
535+
536+
Parameters
537+
----------
538+
num_walkers : int
539+
How many walkers (with equal number of samples) compose
540+
this chain.
541+
i : int,optional
542+
The index of the chain you wish to divide
543+
544+
Returns
545+
-------
546+
ChainConsumer
547+
A new ChainConsumer instance with the same settings as the parent instance, containing
548+
``num_walker`` chains.
549+
"""
492550
cs = np.split(self.chains[i], num_walkers)
493551
ws = np.split(self.weights[i], num_walkers)
494552
con = ChainConsumer()

doc/chain_api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
Chain Consumer API
66
==================
77

8+
.. autosummary:: chainconsumer.ChainConsumer
9+
:members:
10+
:undoc-members:
11+
812
.. autoclass:: chainconsumer.ChainConsumer
913
:members:
1014
:undoc-members:

doc/index.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
ChainConsumer
33
=============
44

5-
I wrote this code after realising that the fantastic library
6-
`corner <https://github.com/dfm/corner.py>`_ could not plot everything I
7-
wanted to plot. And so here we are!
5+
ChainConsumer is a python package designed to do one thing - consume the chains
6+
output from Monte Carlo processes like MCMC. ChainConsumer can utilise these chains
7+
to produce plots of the posterior surface inferred from the chain distributions,
8+
to plot the chains as walks (to check for mixing and convergence), and to output
9+
parameter summaries in the form of LaTeX tables.
810

911
To get things started, here is a basic example:
1012

@@ -38,10 +40,24 @@ Contents
3840
chain_api
3941
examples/index
4042

43+
Installation
44+
------------
45+
4146
ChainConsumer requires the following dependencies:
4247

4348
.. literalinclude:: ../requirements.txt
4449

4550
ChainConsumer can be installed as follows::
4651

47-
pip install chainconsumer
52+
pip install chainconsumer
53+
54+
Contributing
55+
------------
56+
57+
Users that wish to contribute to this project may do so in a number of ways.
58+
Firstly, for any feature requests, bugs or general ideas, please raise an issue
59+
via `Github <https://github.com/samreay/ChainConsumer/issues>`_.
60+
61+
If you wish to contribute code to the project, please simple fork the project on
62+
Github and then raise a pull request. Pull requests will be reviewed to determine
63+
whether the changes are major or minor in nature, and to ensure all changes are tested.

doc/make.bat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,16 @@ if "%1" == "html" (
8686
goto end
8787
)
8888

89+
if "%1" == "htmlfull" (
90+
%SPHINXBUILD% -E -a -b html %ALLSPHINXOPTS% %BUILDDIR%/html
91+
if errorlevel 1 exit /b 1
92+
echo.
93+
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
94+
goto end
95+
)
96+
8997
if "%1" == "rst" (
90-
sphinx-apidoc -fM -o . ../dessn
98+
sphinx-apidoc -fM -o . ../chainconsumer
9199
if errorlevel 1 exit /b 1
92100
echo.
93101
echo.Made rst

paper/paper.bib

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ @article{matplotlib
99
doi = {10.1109/MCSE.2007.55}
1010
}
1111

12+
@Misc{scipy,
13+
author = {Eric Jones and Travis Oliphant and Pearu Peterson and others},
14+
title = {{SciPy}: Open source scientific tools for {Python}},
15+
year = {2001--},
16+
url = "http://www.scipy.org/"
17+
}
18+
19+
@article{numpy,
20+
author = {Walt, Stefan van der and Colbert, S. Chris and Varoquaux, Gael},
21+
title = {The NumPy Array: A Structure for Efficient Numerical Computation},
22+
journal = {Computing in Science and Engg.},
23+
issue_date = {March 2011},
24+
volume = {13},
25+
number = {2},
26+
month = mar,
27+
year = {2011},
28+
issn = {1521-9615},
29+
pages = {22--30},
30+
numpages = {9},
31+
url = {http://dx.doi.org/10.1109/MCSE.2011.37},
32+
doi = {10.1109/MCSE.2011.37},
33+
acmid = {1957466},
34+
publisher = {IEEE Educational Activities Department},
35+
address = {Piscataway, NJ, USA},
36+
keywords = {NumPy, Python, Python, NumPy, scientific programming, numerical computations, programming libraries, numerical computations, programming libraries, scientific programming},
37+
}
1238
@online{github,
1339
author = {Samuel Hinton},
1440
title = {ChainConsumer},
@@ -22,5 +48,5 @@ @misc{zenodo
2248
title = {ChainConsumer},
2349
doi = {10.5281/zenodo.58511},
2450
year = 2016,
25-
howpublished = {\url{http://dx.doi.org/10.5281/zenodo.58511}}
51+
howpublished = {\url{http://dx.doi.org/10.5281/zenodo.60315}}
2652
}

paper/paper.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"author": [
55
"Samuel Hinton"
66
],
7-
"identifier": "http://dx.doi.org/10.5281/zenodo.58511",
7+
"identifier": "http://dx.doi.org/10.5281/zenodo.60315",
88
"codeRepository": "https://github.com/samreay/ChainConsumer",
99
"datePublished": "2016-07-24",
10-
"dateModified": "2016-07-24",
10+
"dateModified": "2016-08-26",
1111
"dateCreated": "2016-07-24",
1212
"description": "A software package to consume chains produced by MCMC and similar algorithms, to provide likelihood surfaces, chain visualisations and parameter summaries in the form of LaTeX tables.",
1313
"keywords": "Python, visualization, mcmc",

paper/paper.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ the functionality to plot the chains as a series of walks in
3131
parameter values, which provides an easy visual check on chain
3232
mixing and chain convergence.
3333

34-
Plotting is performed via the matplotlib library [@matplotlib].
34+
Plotting is performed via the matplotlib library [@matplotlib], and
35+
makes use of various numpy [@numpy] and scipy [@scipy] functions.
3536

3637
Code archives can be found on Zenodo at [@zenodo] and any
3738
bugs or feature requests can be opened as issues on the Github

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def run_tests(self):
4747
author="Samuel Hinton",
4848
author_email="[email protected]",
4949
requires=["numpy", "scipy", "matplotlib", "statsmodels"],
50+
install_requires=["numpy", "scipy", "matplotlib", "statsmodels"],
5051
tests_require=["pytest","pytest-cov"],
5152
cmdclass={"test": PyTest},
5253
)

0 commit comments

Comments
 (0)