Nested Sampling Implementation Package

Here are listed all the modules that can be found in my little package about Nasted Sampling.

Note

To use the package, once you have cloned the repository, go to Nested Sampling directory where there is setup.py and run

python install .

Modules

nested_sampling.ns_gaussian module

Python implementation of Nested Sampling (Skilling 2004) in order to compute the integral of a N-dim gaussian

nested_sampling.ns_gaussian.nested_samplig(live_points, dim, boundary, proposal_distribution, verbose=False)[source]

Nested Sampling by Skilling (2004)

Parameters
  • live_points (numpy array) – Numpy array of dimension (number of live points, dimension + 2). From column 0 to d(=dimension) the vectors of parameter sampled from the parameter space are placed, column d+1 corresponds to the priors value and the last to the likelihood values

  • dim (int) – Dimension of the parameter space.

  • resample_function (str) – Choose between uniform or normal resample distribution

  • verbose (bool) – Print some information. The default is False

Returns

  • area (numpy array) – Array of the area elements accumulated during iterations

  • Zlog (list) – List of two list: logZ + error and logZ - error. They are used for plots

  • logL_worst (list) – List of the worst likelihoods obtained during iterations. They are the values that define the profile of the likelihood used in the actual computation of the Riemann sum

  • prior_mass (list) – List of the value of the prior mass accumulated during the iteration

  • T (list) – List of times required for sample the new objects with the proposal function

  • steps (int) – Number of steps required

  • accepted, rejected (int) – Accepted and rejected points over the whole NS run. They are the sum of all the accepted/rejected points during the sampling of the new object in the proposal function

  • logH_list (list) – List of information values accumulated during iterations

  • error (int) – Estimated error on the evidence. It is a first approximation based on the standard deviation of the prior mass values (the one found statistically, see Nested Sampling (Skilling 2004))

nested_sampling.functions module

Functions to be used for the nested sampling algorithm (Skilling 2004)

nested_sampling.functions.autocorrelation(x, max_lag, bootstrap=False)[source]

Simple implementation for the autocorrelation function.

Parameters
  • x (numpy array or list) – Input array for the autocorrelation function

  • max_lag (int) – Maximum lag to be used for the AC

  • bootstrap (bool) – Compute the bootstrap test

Returns

auto_corr – Autocorrelation function

Return type

numpy array

nested_sampling.functions.log_likelihood(x, dim, init)[source]

Return the logarithm of a N-dimensional gaussian likelihood. It is set in such a way that the integral of the product with the prior over the parameter space is 1.

Parameters
  • x (numpy.array) – If init is set to True, x should be a MxN matrix whose M rows (number of points) are random N-dimensional vectors. In this case it is used to initialize the likelihood of the live points. If init is set to False, x should be just a random N dimensional vector.

  • dim (int) – Dimension of the parameter space.

  • init (bool) – You can choose to use the funcion to initialize the likelihood of the live points (True) or to generate just a new likelihood value (False)

Returns

Likelihood – Likelihood values or singole likelihood value

Return type

list or float

nested_sampling.functions.proposal(x, dim, boundary, std, distribution)[source]

Sample a new object from the prior subject to the constrain L(x_new) > Lworst_old

Parameters
  • x (numpy array) – Array (parameter, prior, likelihood) corresponding to the worst likelihood

  • dim (int) – Dimension of the parameter space.

  • logLmin (float64) – Worst likelihood, i.e. The third element of x

  • std (float) – Limits of the uniform distribution proposal or standard deviation of the normal/anglit distribution. The name comes from the fact that it correspondsto the mean of standard deviations of the points along the axis of the parameter space

  • distribution (string) – Choose the distribution from which the new object should be sampled. Available options are ‘uniform’, ‘normal’

Returns

  • new_line (numpy array) – New sampled object that satisfies the likelihood constrain

  • t (float) – Seconds required for the resampling

  • accepted, rejected (int) – Accepted/rejected number of points during the resampling

nested_sampling.comparision_plot module

nested_sampling.comparision_plot.comparision_plot(range_dim, true_values, proposal=[0, 1], folder_values_path='results/')[source]

Plot the logarithm of the evidence for dimension in range_dim and the total time required to complete the integration

Parameters
  • folder_values_path (str, optional) – Path of the folder. The default is ‘results/’

  • proposal (list, optional) – List of the proposal distribution using the notation of nested_sampling.py: 0 for uniform and 1 for normal. The default is [0,1]

  • true_values (list) – List of the theoretical values of the integral for the evidence

  • range_dim (numpy array) – Array of dimension used for the integration in nested_sampling.py

Returns

Return type

None