professor is hosted by Hepforge, IPPP Durham

professor.interpolation

Introduction

The interpolation sub-package contains the data structures for the bin-wise parameterization of the MC response function. Four objects are designed for external usage and are available in professor.user:

addIpolCLOptions()
Add an OptionGroup with common options to an command line parser.
BinDistribution
A simple container for the MC run data of a single bin.
InterpolationSet
Container for all bin-wise interpolations for one set of anchor points. Used for persistency.

Examples

Load an interpolation set from a file.

>>> ipolset = prof.InterpolationSet.fromPickle("path/to/file.pkl")

Documentation

professor.interpolation.addIpolCLOptions(optparser, weaveswitch=False)

Add an OptionGroup with common options to an command line parser.

class professor.interpolation.BinDistribution(paramnames, binid, binrange, data=None)

Bases: list

Container class for the distribution of MC bin contents.

This class stores the distribution of the MC response of one bin for varying MC model parameters.

Examples

>>> bindist = prof.BinDistribution(['dummy-par1', 'dummy-par2'], 'dummy-obs',
...                                dummy_bin.getXRange())
>>> # populate the distribution...
>>> bindist.addRun(param, bin)
>>> for param, bin in bindist:
>>>     # do whatever you need here

Methods

Create a new BinDistribution.

Parameters :

paramnames : list of str

The parameter names.

binid : str

The bin id, i.e. /Histo/Path:BinIndex.

binrange : tuple of floats

The x-range of the bin.

data : list of (ParameterPoint, Bin) tuples, optional

Initialise the new instance with this values.

Methods

addRun(params, bin)

Add a MC run to the distribution.

Parameters :

params : ParameterPoint

The model parameters used in this run.

bin : Bin

The MC prediction in this bin.

Raises :

ParameterError :

If params does not match the previously added parameters points.

getMedianMCError()

Calculate the median error of the MC data.

getName()

Get the bin id.

getRanges()

Get the parameter ranges spanned by the stored runs.

numberOfRuns()
class professor.interpolation.InterpolationSet(ranges, runskey, ipolmethod, ipols=None)

Bases: dict

Container for all bin-wise interpolations for one set of anchor points. Used for persistency.

The object is an extended dict. Keys are bin identifiers, values bin interpolations.

The following factory functions are available: * mkFromBinDists() * mkFromPickle()

Attributes

class professor.interpolation.interpolation.GenericBinInterpolation(bd=None, center=None, order=None)

Bases: object

Generic class for bin-wise interpolation of the MC response function.

Tailored for polynomial interpolations. The matrix of interpolation coefficients is stored. And a method to compute the extended parameter vector is available.

A new interpolation is created from a BinDistribution instance with the standard constructor __init__(). This method calculates the matrix of coefficients.

Note

The constructor can be called only with the “order=...” argument, e.g. to calculate the number of minimum MC-runs with the created instance.

Methods

Creates an interpolation object.

At least ‘order’ needs to be specified for object creation. Data can be provided optional in form of a bin distribution.

Parameters :

bd : BinDistribution, optional

The distribution of the MC response function.

center : ParameterPoint, optional

The center of the interpolation. If `None`the center of the hyper cube spanned by the anchor points is used.

order : int, str

Interpolation order. Given either by word (“linear, quadratic”,...) or polyN with N being the order of the polynom used for interpolation.

Methods

fillFromBinDistribution(bd=None, center=None)

Fill an empty interpolation from a bin distribution. Will overwrite previous bin data!

This calculates the interpolation coefficients.

Parameters :

bd : BinDistribution

The distribution of the MC response function.

center : ParameterPoint, optional

The center of the interpolation. If None the center of the hyper cube spanned by the anchor points is used.

getBin(p, error=True)

Get the interpolated bin.

Parameters :

p : numpy.ndarray

The parameter vector.

Returns :

bin : Bin

getBinCenter()
getCoefficient(comb)

Get coefficient to specific parameter combination given by comb.

As a side-effect self.coeffs is provided, which is an ordered list of all possible combinations (o1,o2,o3,...) with ox’s being the order of the x-th parameter characterizing a term in the polynomial.

Parameters :

comb: Tuple, containing order of parameters in this combination. :

E.g. with 3 parameters: (2,1,4) means coefficient to x^2*y*z^4 in a polynomial with (at least) order 7. Constraints: every element in comb > 0, sum(comb) <= self.order

getGradient(params, k=-1)

Return gradient of polynomial characterized by coefficients (memory) for given ‘params’. If given dimension ‘k’ only the k-th component is computed.

Parameters :

params: array-like :

k: positive integer :

getLongVector(p)

Make an extended parameter vector.

Polynomials are split into parts of same order. Generating functions (lambda) for these parts are created once per order and stored in a dict. In case the same class/object is used multiple times the stored functions will be used.

TODO: Maybe a numpy-equivalent can be found for the by-order-creation task which would speed-up the pure-python implementation. (Anyway this might not be used because of the C-implementation).

Parameters :p : numpy.ndarray
getValue(p)

Get the interpolation value.

Parameters :p : array_like
Returns :val : float
minNumOfRuns(dim)

Get the minimal number of runs necessary.

Parameters :dim : int
numOfCoefficients(dim)

The number of coefficients for a dim dimensional space.

Parameters :dim : int

Table Of Contents

Previous topic

professor.fitfunctions

Next topic

professor.minimize

This Page