ConvPDFs

class minkit.ConvPDFs(name, first, second, range=None)[source]

Bases: minkit.MultiPDF

Represent the convolution of two different PDFs.

Parameters
  • name (str) – name of the PDF.

  • first (PDF) – first PDF.

  • second (PDF) – second PDF.

  • range (str) – range of the convolution. This is needed in case part of the PDFs lie outside the evaluation range. It is set to “full” by default.

Attributes Summary

BIND

CACHE_TYPES

CONST

all_args

All the argument parameters associated to this class.

all_pars

All the parameters associated to this class.

all_pdfs

Recursively get all the possible PDFs belonging to this object.

all_real_args

All the argument parameters that are not ParameterFormula instances.

aop

Object to do operations on arrays.

args

Argument parameters this object directly depends on.

backend

Backend interface.

cache

Return the cached values for this PDF.

cache_type

Cache type being used.

constant

Whether this is a constant PDF.

data_pars

Data parameters this object directly depends on.

dependencies

Registry of PDFs this instance depends on.

dependent

interpolation_method

Function used to do the interpolation.

pdfs

Get the registry of PDFs within this class.

real_args

Arguments that do not depend on other arguments.

Methods Summary

__call__(data[, range, normalized])

Call the PDF in the given set of data.

bind([range, normalized])

Prepare an object that will be called many times with the same set of values.

component(name)

Get the PDF object with the given name.

convolve([normalized])

Calculate the convolution.

copy([backend])

Create a copy of this PDF.

evaluate_binned(data[, normalized])

Evaluate the PDF over a binned sample.

from_json_object(obj, pars, pdfs)

Build a PDF from a JSON object.

generate([size, mapsize, gensize, …])

Generate random data.

get_values()

Get the values of the parameters within this object.

integral([integral_range, range])

Calculate the integral of a PDF.

norm([range])

Calculate the normalization of the PDF.

numerical_integral([integral_range, range])

Calculate the integral of a PDF.

numerical_normalization([range])

Calculate a numerical normalization.

restoring_state()

Enter a context where the attributes of the parameters will be restored on exit.

set_values(**kwargs)

Set the values of the parameters associated to this PDF.

to_backend(backend)

Initialize this class in a different backend.

to_json_object()

Dump the PDF information into a JSON object.

using_cache(ctype)

Safe method to enable a cache of the PDF.

Attributes Documentation

BIND = 'bind'
CACHE_TYPES = ('bind', 'const')
CONST = 'const'
all_args

All the argument parameters associated to this class.

Type

Registry(Parameter)

all_pars

All the parameters associated to this class. This includes also any ParameterFormula and the data parameters.

Type

Registry(Parameter)

all_pdfs

Recursively get all the possible PDFs belonging to this object.

all_real_args

All the argument parameters that are not ParameterFormula instances.

Type

Registry(Parameter)

aop

Object to do operations on arrays.

Type

ArrayOperations

args

Argument parameters this object directly depends on.

Type

Registry(Parameter)

backend

Backend interface.

Type

Backend

cache

Return the cached values for this PDF.

Type

dict

cache_type

Cache type being used.

Type

str or None

constant

Whether this is a constant PDF.

Type

bool

data_pars

Data parameters this object directly depends on.

Type

Registry(Parameter)

dependencies

Registry of PDFs this instance depends on.

Type

Registry(PDF)

dependent = True
interpolation_method

Function used to do the interpolation.

Getter

Function used to do the interpolation.

Setter

Set the function to use from a string.

pdfs

Get the registry of PDFs within this class.

Returns

PDFs owned by this class.

Return type

Registry(PDF)

real_args

Arguments that do not depend on other arguments.

Type

Registry(Parameter)

Methods Documentation

__call__(data, range='full', normalized=True)[source]

Call the PDF in the given set of data.

Parameters
  • data (DataSet or BinnedDataSet) – data to evaluate.

  • range (str) – normalization range.

  • normalized (bool) – whether to return a normalized output.

Returns

Evaluation of the PDF.

Return type

darray

bind(range='full', normalized=True)

Prepare an object that will be called many times with the same set of values. This is usefull for PDFs using a cache, to avoid creating it many times in sucessive calls to PDF.__call__().

Parameters
  • range (str) – normalization range.

  • normalized (bool) – whether to return a normalized output.

component(name)

Get the PDF object with the given name.

Parameters

name (str) – name of the PDF.

Returns

Component with the given name.

Return type

PDF

convolve(normalized=True)[source]

Calculate the convolution.

Parameters
  • range (str) – normalization range.

  • normalized (bool) – whether to return a normalized output.

Returns

Data and result of the evaluation.

Return type

numpy.ndarray, numpy.ndarray

copy(backend=None)

Create a copy of this PDF.

Parameters

backend (Backend) – new backend.

Returns

A copy of this PDF.

evaluate_binned(data, normalized=True)[source]

Evaluate the PDF over a binned sample.

Parameters
  • data (BinnedDataSet) – input data.

  • normalized (bool) – whether to normalize the output array or not.

Returns

Values from the evaluation.

Return type

farray

classmethod from_json_object(obj, pars, pdfs)[source]

Build a PDF from a JSON object. This object must represent the internal structure of the PDF.

Parameters
  • obj (dict) – JSON object.

  • pars (Registry) – parameter to build the PDF.

  • backend (Backend) – backend to build the PDF.

Returns

This type of PDF constructed together with its parameters.

generate(size=10000, mapsize=1000, gensize=None, safe_factor=1.1, range='full')

Generate random data. A call to PDF.bind() is implicit, since several calls will be done to the PDF with the same sets of values.

Parameters
  • size (int) – size (or minimum size) of the output sample.

  • mapsize (int) – number of points to consider per dimension (data parameter) in order to calculate the maximum value of the PDF.

  • gensize (int) – number of entries to generate per iteration.

  • safe_factor (float) – additional factor to multiply the numerically calculated maximum of the function. In general this must be modified if the function is not well-behaved.

  • range (str) – range of the data parameters where to generate data.

Returns

Output sample.

Return type

DataSet

get_values()

Get the values of the parameters within this object.

Returns

Dictionary with the values of the parameters.

Return type

dict(str, float)

integral(integral_range='full', range='full')

Calculate the integral of a PDF.

Parameters
  • integral_range (str) – range of the integral to compute.

  • range (str) – normalization range to consider.

Returns

Integral of the PDF in the range defined by “integral_range” normalized to “range”.

Return type

float

norm(range='full')[source]

Calculate the normalization of the PDF.

Parameters

range (str) – normalization range to consider.

Returns

Value of the normalization.

Return type

float

numerical_integral(integral_range='full', range='full')[source]

Calculate the integral of a PDF.

Parameters
  • integral_range (str) – range of the integral to compute.

  • range (str) – normalization range to consider.

Returns

Integral of the PDF in the range defined by “integral_range” normalized to “range”.

Return type

float

numerical_normalization(range='full')[source]

Calculate a numerical normalization.

Parameters

range (str) – normalization range.

Returns

Normalization.

Return type

float

restoring_state()

Enter a context where the attributes of the parameters will be restored on exit.

set_values(**kwargs)

Set the values of the parameters associated to this PDF.

Parameters

kwargs (dict(str, float)) – keyword arguments with “name”/”value”.

Note

Any PDF sharing parameters with this will also change its behaviour.

to_backend(backend)[source]

Initialize this class in a different backend.

Parameters

backend (Backend) – new backend.

Returns

An instance of this class in the new backend.

to_json_object()[source]

Dump the PDF information into a JSON object. The PDF can be constructed at any time by calling PDF.from_json_object().

Returns

Object that can be saved into a JSON file.

Return type

dict

using_cache(ctype)

Safe method to enable a cache of the PDF. There are two types of cache:

  • const: it means that we plan to call the PDF consecutively in the same data set, but the value of the parameters that are not constant is allowed to change. This means that any PDF that has all its arguments as constant is assumed to have the same value in each evaluation.

  • bind: this is reserved for those processes where the normalization range will be the same, as well as the values of the parameters of the PDF. However, the function can be called in different data sets.

Warning

It is responsibility of the user to ensure that the conditions for the cache to be valid are preserved.

Parameters

ctype (str) – cache type.