Skip to content
Snippets Groups Projects
Commit 3ef7e49a authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Add evidences to corner plots and fix a few minor bugs

parent 30087a54
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@ def setup_command_line_args():
help="List of labels to use for each result.")
parser.add_argument("-p", "--parameters", nargs='+', default=None,
help="List of parameters.")
parser.add_argument("-e", "--evidences", action='store_true', default=False,
help="Add the evidences to the legend.")
args, _ = parser.parse_known_args()
return args
......@@ -24,4 +26,5 @@ def main():
for r in args.results]
tupak.core.result.plot_multiple(results, filename=args.filename,
labels=args.labels,
parameters=args.parameters)
parameters=args.parameters,
evidences=args.evidences)
......@@ -409,7 +409,7 @@ class Result(dict):
def plot_multiple(results, filename=None, labels=None, colours=None,
save=True, **kwargs):
save=True, evidences=False, **kwargs):
""" Generate a corner plot overlaying two sets of results
Parameters
......@@ -432,6 +432,9 @@ def plot_multiple(results, filename=None, labels=None, colours=None,
All other keyword arguments are passed to `result.plot_corner`.
However, `show_titles` and `truths` are ignored since they would be
ambiguous on such a plot.
evidences: bool, optional
Add the log-evidence calculations to the legend. If available, the
Bayes factor will be used instead.
Returns
-------
......@@ -460,6 +463,14 @@ def plot_multiple(results, filename=None, labels=None, colours=None,
if labels is None:
labels = default_labels
if evidences:
if np.isnan(results[0].log_bayes_factor):
template = ' $\mathrm{{ln}}(Z)={:1.3g}$'
else:
template = ' $\mathrm{{ln}}(B)={:1.3g}$'
for i, label in enumerate(labels):
labels[i] = label + template.format(results[i].log_bayes_factor)
axes = fig.get_axes()
ndim = int(np.sqrt(len(axes)))
axes[ndim-1].legend(lines, labels)
......
......@@ -353,7 +353,7 @@ class Sampler(object):
for k in kwargs_print:
if type(kwargs_print[k]) in (list, np.ndarray):
array_repr = np.array(kwargs_print[k])
if array_repr.shape > 10:
if array_repr.size > 10:
kwargs_print[k] = ('array_like, shape={}'
.format(array_repr.shape))
logging.info("Using sampler {} with kwargs {}".format(
......@@ -776,7 +776,7 @@ class Emcee(Sampler):
if 'pos0' in self.kwargs:
logging.debug("Using given initial positions for walkers")
pos0 = np.squeeze(self.kwargs['pos0'])
if pos0.shape != (self.ndim, self.nwalkers):
if pos0.shape != (self.nwalkers, self.ndim):
raise ValueError(
'Input pos0 should be of shape ndim, nwalkers')
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment