BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class SampleList( list )Source

SampleList is a list of Samples, see Sample

SampleList is the main result of the NestedSampler. It contains all information to calculate averages, medians, modi or maximum likihood solutions of the parameters, or of any function of the parameters; in particular of the Model.

To make averages one has to take into account the weights. Each Sample has a weight and all weights sum to 1.0. So the average of any function, f, of the parameters p is

     E( f(p) ) = ∑ wk f( pk )

where the sum is over all samples k.

A large set of utility functions is provided to extract the information from the SampleList.

Attributes

  • parameters : numpy.array (read-only)
         The average over the parameters. Not for dynamic models.

  • stdevs, standardDeviations : numpy.array (read-only)
         The standard deviations for the parameters. Not for dynamic models

  • scale : float
         The average of the noise scale

  • stdevScale : float
         the standard deviation of the scale.

  • logZ : float (read-only)
         Natural log of evidence

  • evidence : float (read-only)
         log10( Z ). Evidence * 10 is interpretable as dB.

  • info : float (read-only)
         The information H. The compression factor ( the ratio of the prior space
         available to the model parameters over the posterior space ) is equal to the exp( H ).

  • maxLikelihoodIndex : int (read-only)
         The index at which the max likelihood can be found: always the last in the list

  • maxLikelihoodParameters : numpy.array (read-only)
         The maximum likelihood parameters at the maxLikelihoodIndex.

  • maxLikelihoodScale : float (read-only)
         The maximum likelihood noise scale at the maxLikelihoodIndex.

  • medianIndex : int (read-only)
         The index at which the median can be found: the middle of the cumulative weights.
         It is calculated once and then kept.

  • medianParameters : numpy.array (read-only)
         The median of the parameters at the medianIndex

  • medianScale : float (read-only)
         The median of the noise scale at the medianIndex

  • modusIndex : int (read-only)
         The index at which the modus can be found: the largest weight
         It is calculated once and then kept.

  • modusParameters : numpy.array (read-only)
         The modus of the parameters at the modusIndex

  • modusScale : float (read-only)
         The modus of the noise scale at the modusIndex.

  • normalized : bool
         True when the weights are normalized to SUM( weights ) = 1

Author Do Kester

SampleList( model, nsamples, parameters=None, fitIndex=None, ndata=1 )

Constructor.

Parameters

  • nsamples : int
         number of samples created.
  • model : Model
         to be used in the samples
  • parameters : array_like
         list of model parameters
  • fitIndex : array of int
         indicating which parameters need fitting
  • ndata : int
         length of the data vector; to be used in stdev calculations

sample( k, sample=None )
Set or return the k-th sample from the list.

Parameters

  • k : int
         the index of the sample
  • sample : Sample
         if present, set the kth sample with sample

normalize( )
Normalize the samplelist. make Sum( weight ) = 1

add( sample )
Add a Sample to the list

Parameters

  • sample : Sample
         the sample to be added

copy( src, des )
Copy one item of the list onto another.

Parameters

  • src : int
         the source item
  • des : int
         the destination item

weed( maxsize=None )
Weed superfluous samples.

If MaxSamples has been set, it is checked whether the size of the SampleList exceeds the maximum. If so the Sample with the smallest log( Weight ) is removed. weed( ) is called recursively until the size has the required length.

logPlus( x, y )
Return log( exp(x) + exp(y) )

getParameters( )
Calculate the average of the parameters and the standard deviations.

Return

     The average values of the parameters. Raises

     ValueError when using Dynamic Models

getHypars( )
Return the hyper parameters

nhp = len( self[0].hyper )

hypar = numpy.zeros( nhp, dtype=float ) hydev = numpy.zeros( nhp, dtype=float ) sw = 0.0 for sample in self
     wt = math.exp( sample.logW )
     sw += wt
     ws = wt * sample.hyper
     hypar = hypar + ws
     hydev = hydev + ws * sample.hyper self.stdevHypars = numpy.sqrt( hydev - hypar * hypar ) self.hypars = hypar return self.hypars

getNuisance( )
Return the average of the nuisance parameters (if present)

averstd( name )
Return the average and the stddevs of the named attribute from Sample

Parameters

  • name : str
         name of an attribute from Sample

getMedianIndex( )
Return the index at which the median can be found.

getMaximumNumberOfParameters( )
Return the maximum number of parameters (for Dynamic Models)

getParameterEvolution( kpar=None )
Return the evolution of one or all parameters.

In case of dynamic models the number of parameters may vary. They are zero-padded. Use getNumberOfParametersEvolution to get the actual number.

Parameters

  • kpar : int or tuple of ints
         the parameter to be selected. Default: all

getParAndWgtEvolution( )
Return the evolution of parameters and weights.

In case of dynamic models the number of parameters may vary. They are zero-padded. Use getNumberOfParametersEvolution to get the actual number.

getNumberOfParametersEvolution( )

Return the evolution of the number of parameters.

getScaleEvolution( )

Return the evolution of the scale.

getLogLikelihoodEvolution( )

Return the evolution of the log( Likelihood ).

getLogWeightEvolution( )
Return the evolution of the log( weight ).

The weights itself sum up to 1. See #getWeightEvolution( ).

getWeightEvolution( )
Return the evolution of the weight.

The weights sum to 1.

getParentEvolution( )

Return the evolution of the parentage.

getStartEvolution( )

Return the evolution of the start generation.

getGeneration( )

Return the generation number pertaining to the evolution.

getLowLogL( )
Return the lowest value of logL in the samplelist, plus its index.

average( xdata )
Return the (weighted) average result of the model(s) over the samples.

Parameters

  • xdata : array_like
         the input

monteCarloError( xdata )
Calculates 1-sigma-confidence regions on the model given some inputs.

The model is run with the input for the parameters in each of the samples. Appropiately weighted standard deviations are calculated and returned at each input value.

Parameters

  • xdata : array_like
        the input vectors.

Returns

  • error : array_like
         standard deviations at each input point