Maths

Mathematics.

Binning

clusterking.maths.binning.bin_function(fct, binning: <sphinx.ext.autodoc.importer._MockObject object at 0x7f9006888dd8>, normalize=False) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f9006888e80>[source]

Bin function, i.e. calculate the integrals of a function for each bin.

Parameters:
  • fct – Function to be integrated per bin
  • binning – Array of bin edge points.
  • normalize – If true, we will normalize the distribution, i.e. divide by the sum of all bins in the end.
Returns:

Array of bin contents

Metric

clusterking.maths.metric.condense_distance_matrix(matrix)[source]

Convert a square-form distance matrix to a vector-form distance vector

Parameters:matrix – n x n symmetric matrix with 0 diagonal
Returns:n choose 2 vector
clusterking.maths.metric.uncondense_distance_matrix(vector)[source]

Convert a vector-form distance vector to a square-form distance matrix

Parameters:vector – n choose 2 vector
Returns:n x n symmetric matrix with 0 diagonal
clusterking.maths.metric.metric_selection(*args, **kwargs) → Callable[source]

Select a metric in one of the following ways:

  1. If no positional arguments are given, we choose the euclidean metric.
  2. If the first positional argument is string, we pick one of the metrics
that are defined in scipy.spatical.distance.pdist by that name (all additional arguments will be past to this function).

3. If the first positional argument is a function, we take this function (and add all additional arguments to it).

Examples:

  • ...(): Euclidean metric
  • ...("euclidean"): Also Euclidean metric
  • ...(lambda data: scipy.spatial.distance.pdist(data.data(), 'euclidean'): Also Euclidean metric
  • ...("minkowski", p=2): Minkowsky distance with p=2.

See https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html for more information.

Parameters:
  • *args
  • **kwargs
Returns:

Function that takes Data object as only parameter and returns a reduced distance matrix.

clusterking.maths.metric.chi2_metric(dwe: clusterking.data.dwe.DataWithErrors, output='condensed')[source]

Returns the chi2/ndf values of the comparison of a datasets.

Parameters:
  • dwe
  • output – ‘condensed’ (condensed distance matrix) or ‘full’ (full distance matrix)
Returns:

Condensed distance matrix

Statistics

clusterking.maths.statistics.ensure_array(x)[source]
clusterking.maths.statistics.cov2err(cov)[source]

Convert covariance matrix (or array of covariance matrices of equal shape) to error array (or array thereof).

Parameters:cov – [n x ] nbins x nbins array
Returns
[n x ] nbins array
clusterking.maths.statistics.cov2corr(cov)[source]

Convert covariance matrix (or array of covariance matrices of equal shape) to correlation matrix (or array thereof).

Parameters:cov – [n x ] nbins x nbins array
Returns
[n x ] nbins x nbins array
clusterking.maths.statistics.corr2cov(corr, err)[source]

Convert correlation matrix (or array of covariance matrices of equal shape) together with error array (or array thereof) to covariance matrix (or array thereof).

Parameters:
  • corr – [n x ] nbins x nbins array
  • err – [n x ] nbins array
Returns
[n x ] nbins x nbins array
clusterking.maths.statistics.rel2abs_cov(cov, data)[source]

Convert relative covariance matrix to absolute covariance matrix

Parameters:
  • cov – n x nbins x nbins array
  • data – n x nbins array
Returns:

n x nbins x nbins array

clusterking.maths.statistics.abs2rel_cov(cov, data)[source]

Convert covariance matrix to relative covariance matrix

Parameters:
  • cov – n x nbins x nbins array
  • data – n x nbins array
Returns:

n x nbins x nbins array