API¶
MCMC Results¶
The best-fit parameter vector can be accessed from the MCMC chain using
the following functions of the EmceeResults
object:
EmceeResults.values () |
Convenience function to return the median values for the free parameters as an array |
EmceeResults.constrained_values () |
Convenience function to return the median values for the constrained parameters as an array |
EmceeResults.max_lnprob_values () |
Return the value of the free parameters at the iteration with the maximum probability |
EmceeResults.max_lnprob_constrained_values () |
Return the value of the constrained parameters at the iteration with the maximum probability |
EmceeResults.peak_values () |
Convenience function to return the peak values for the free parameters as an array |
EmceeResults.peak_constrained_values () |
Convenience function to return the peak values for the constrained parameters as an array |
The results object can be saved and loaded from file using:
EmceeResults.to_npz (filename, **meta) |
Save the relevant information of the class to a numpy npz file |
EmceeResults.from_npz (filename) |
Load a numpy npz file and return the corresponding EmceeResults object |
Correlations between parameters can be analyzed using:
EmceeResults.sorted_1d_corrs ([params, …]) |
Return a pandas DataFrame holding the correlation matrix, as computed from the chains DataFrame, for all parameters |
EmceeResults.corr ([params, labels, use_latex]) |
Return a pandas DataFrame holding the correlation matrix, as computed from the chains DataFrame, for all parameters |
The results can be visualized with the following function, which take
advantage of the seaborn
Python plotting module:
EmceeResults.jointplot_2d (param1, param2[, …]) |
Plot the 2D traces of the given parameters, using KDE via the seaborn.jointplot() function. |
EmceeResults.kdeplot_2d (param1, param2[, …]) |
Plot the 2D traces of the given parameters, using KDE via seaborn.kdeplot() |
EmceeResults.plot_correlation ([params, …]) |
Plot the diagonal correlation matrix, using seaborn.heatmap |
EmceeResults.plot_timeline (*names, **kwargs) |
Plot the chain timeline for as many parameters as specified in the names tuple. |
EmceeResults.plot_triangle (*names, **kwargs) |
Make a triange plot for the desired parameters using the corner.corner() function. |
-
class
pyRSD.rsdfit.results.
EmceeResults
(sampler, fit_params, burnin=None, **meta)¶ Class to hold the fitting results from an emcee MCMC run
-
as_dict
(kind=None)¶ Return a dictionary of the values, either the median, peak, or max_lnprob
-
burnin
¶ The number of iterations to treat as part of the “burnin” period, where the chain hasn’t stabilized yet
-
chains
(params=[], labels={}, use_latex=False)¶ Return a pandas DataFrame holding the chains (flat traces) as columns for both the free and constrained parameters
Note that any burnin is removed from the chains.
Parameters: params : list, {‘free’, ‘constrained’}, optional
return only a subset of the parameters
use_latex : bool, optional
If True, try to use any available latex names for the tick labels; default is False
Returns: DataFrame :
the DataFrame holding the flat traces for all parameters
-
constrained_values
()¶ Convenience function to return the median values for the constrained parameters as an array
-
copy
()¶ Return a deep copy of the EmceeResults object
-
corr
(params=[], labels={}, use_latex=False)¶ Return a pandas DataFrame holding the correlation matrix, as computed from the
chains
DataFrame, for all parametersParameters: params : list, {‘free’, ‘constrained’}, optional
return only a subset of the parameters
use_latex : bool, optional
If True, try to use any available latex names for the tick labels; default is False
Returns: DataFrame (Np, Np) :
the DataFrame holding the correlation between parameters
-
error_rescaling
¶ Rescale error on parameters due to covariance matrix from mocks
-
classmethod
from_npz
(filename)¶ Load a numpy
npz
file and return the correspondingEmceeResults
object
-
iterations
¶ The number of iterations performed, as computed from the chain
-
jointplot_2d
(param1, param2, thin=1, rename={}, crosshairs={}, **kwargs)¶ Plot the 2D traces of the given parameters, using KDE via the
seaborn.jointplot()
function.Parameters: param1 : str
the name of the first parameter
param2 : str
the name of the second parameter
thin : int, optional
thin the plotted array randomly by this amount
rename : dict, optional
dictionary giving a string to rename each variable; default will try to use any latex names stored
crosshairs : dict, optional
values to show as horizontal or vertical lines
**kwargs :
additional keyword arguments to pass to
seaborn
Notes
Any iterations during the “burnin” period are excluded
-
kdeplot_2d
(param1, param2, thin=1, rename={}, crosshairs={}, **kwargs)¶ Plot the 2D traces of the given parameters, using KDE via
seaborn.kdeplot()
Parameters: param1 : str
the name of the first parameter
param2 : str
the name of the second parameter
thin : int, optional
thin the plotted array randomly by this amount
rename : dict, optional
dictionary giving a string to rename each variable; default will try to use any latex names stored
crosshairs : dict, optional
values to show as horizontal or vertical lines
**kwargs :
additional keyword arguments to pass to
seaborn
Notes
Any iterations during the “burnin” period are excluded
-
max_lnprob
¶ The value of the maximum log probability
-
max_lnprob_constrained_values
()¶ Return the value of the constrained parameters at the iteration with the maximum probability
-
max_lnprob_values
()¶ Return the value of the free parameters at the iteration with the maximum probability
-
ndim
¶ The number of free parameters
-
peak_constrained_values
()¶ Convenience function to return the peak values for the constrained parameters as an array
-
peak_values
()¶ Convenience function to return the peak values for the free parameters as an array
-
plot_correlation
(params=[], use_latex=True, labelsize=10)¶ Plot the diagonal correlation matrix, using
seaborn.heatmap
Parameters: params : list, {‘free’, ‘constrained’}, optional
return only a subset of the parameters
use_latex : bool, optional
If True, try to use any available latex names for the tick labels; default is True. You might want to set this to False if you are trying to use mpld3
-
plot_timeline
(*names, **kwargs)¶ Plot the chain timeline for as many parameters as specified in the names tuple.
This plots the value of each walker as a function of iteration.
Parameters: names : tuple
The string names of the parameters to plot
outfile : str, optional
If not None, save the resulting figure with the specified name
Returns: fig : matplotlib.Figure
The figure object
Notes
Any iterations during the “burnin” period are excluded
-
plot_triangle
(*names, **kwargs)¶ Make a triange plot for the desired parameters using the
corner.corner()
function.Parameters: names : tuple
The string names of the parameters to plot
thin : int, optional
The factor to thin the number of samples plotted by. Default is 1 (plot all samples)
outfile : str, optional
If not None, save the resulting figure with the specified name
Returns: fig : matplotlib.Figure
The figure object
Notes
Any iterations during the “burnin” period are excluded
-
sorted_1d_corrs
(params=[], use_latex=False, absval=False)¶ Return a pandas DataFrame holding the correlation matrix, as computed from the
chains
DataFrame, for all parametersParameters: params : list, {‘free’, ‘constrained’}, optional
return only a subset of the parameters
use_latex : bool, optional
If True, try to use any available latex names for the tick labels; default is False
Returns: DataFrame (Np, Np) :
the DataFrame holding the correlation between parameters
-
summarize_fit
()¶ Summarize the fit, by plotting figures and outputing the relevant information
-
to_npz
(filename, **meta)¶ Save the relevant information of the class to a numpy
npz
file
-
values
()¶ Convenience function to return the median values for the free parameters as an array
-
verify_param_ordering
(free_params, constrained_params)¶ Verify the ordering of EmceeResults.chain, making sure that the chains have the ordering specified by free_params and constrained_params
-
walkers
¶ The number of walkers, as computed from the chain
-
-
class
pyRSD.rsdfit.results.
EmceeParameter
(name, trace, burnin=0)¶ Class to hold the parameter fitting result
-
burnin
¶ The number of iterations to exclude as part of the “burn-in” phase
-
error_rescaling
¶ Rescale errors by this factor
-
fiducial
¶ The fiducial value of the parameter
-
flat_trace
¶ Returns the flattened chain, excluding steps that occured during the “burnin” period
-
mean
¶ Return the average value of the chain
-
median
¶ Return the median of the trace, i.e., the 50th percentile of the trace
-
one_sigma
¶ Return the lower and upper one-sigma error intervals
These are computed from the percentiles,
50 - 15.86555
and84.13445 - 50
Returns: lower, upper
The lower and upper 1-sigma error intervals
-
peak
¶ Return the value of the parameter that gives the peak of the posterior PDF, as determined through Gaussian kernel density estimation
-
stderr
¶ The one-sigma standard error, averaging the lower and upper bounds
-
three_sigma
¶ Return the lower and upper three-sigma error intervals
There are computed from the percentiles,
50 - 0.135
and99.865 - 50
Returns: lower, upper
The lower and upper 3-sigma error intervals
-
trace
(niter=None)¶ Return the sample values at a specific iteration number.
shape: (nwalkers, niters)
-
two_sigma
¶ Return the lower and upper two-sigma error intervals.
These are computed from the percentiles,
50 - 2.2775
and97.7225 - 50
Returns: lower, upper
The lower and upper 2-sigma error intervals
-
NLOPT Results¶
-
class
pyRSD.rsdfit.results.
LBFGSResults
(data, fit_params)¶ Class to hold the fitting results from an scipy.optimize L-BFGS-B nonlinear optimization run.
-
copy
()¶ Return a deep copy of the
LBFGSResults
object
-
classmethod
from_npz
(filename)¶ Load a numpy
npz
file and return the correspondingLBFGSResults
object
-
iterations
¶ The total number of iterations ran
-
ndim
¶ The number of free parameters
-
summarize_fit
(*args, **kwargs)¶ Summarize the fit by printing self
-
to_npz
(filename)¶ Save the relevant information of the class to a numpy
npz
file
-
verify_param_ordering
(free_params, constrained_params)¶ Verify the ordering of of parameters, making sure that the ordering specified by free_params and constrained_params is respected in the results
-