# professor2 package¶

## professor2.chi2 module¶

professor2.chi2.chi2_hist(ihist, dhist, params, errmaxs=None)
professor2.chi2.chi2_tot(ihists, dhists, params, hnames=None, errmaxs={})

## professor2.core module¶

class professor2.core.Ipol

Bases: object

An interpolation of a scalar function built from a list of values across a set of parameter point anchors.

The main workhorse object in Professor. The interpolation coefficients are calculated lazily, i.e. when first used.

coeffs
der()

Ipol.derivative(self, *params)

derivative(self, *params)
dim
grad()

gradient(self, *params)
name
order
setMaxParamVals(self, pmaxs)

Set the maximum param values via a list of values ordered cf. the param names. Used in SVD internal scaling.

setMinParamVals(self, pmins)

Set the minimum param values via a list of values ordered cf. the param names. Used in SVD internal scaling.

setParamLimits(self, pmins, pmaxs)

Set the minimum and maximum param values via 2 lists ordered cf. the param names. Used in SVD internal scaling.

toString(self, name='')

Produce a persistent string representing this Ipol object

val()

Ipol.value(self, *params, vmin=None, vmax=None) Calculate the value of this interpolation at the given params point,

forcing return within the range vmin..vmax.

params can be an expanded tuple of floats, an unexpanded iterable of floats, or an ordered dict of paramname -> value.

value(self, *params, vmin=None, vmax=None)

Calculate the value of this interpolation at the given params point, forcing return within the range vmin..vmax.

params can be an expanded tuple of floats, an unexpanded iterable of floats, or an ordered dict of paramname -> value.

class professor2.core.ParamPoints

Bases: object

professor2.core.numCoeffs(dim, order)
professor2.core.version(astuple=False)

Professor version code, as a string by default or a tuple on request

## professor2.dataio module¶

professor2.dataio.find_maxerrs(histos)

Helper function to find the maximum error values found for each bin in the histos double-dict.

histos is a nested dict of DataHisto objects, indexed first by histo path and then by run name, i.e. it is the second of the two objects returned by read_histos().

Returns a dict of lists of floats, indexed by histo path. Each list of floats contains the max error size seen for each bin of the named observable, across the collection of runs histos.keys().

This functions is useful for regularising chi2 etc. computation by constraining interpolated uncertainties to within the range seen in the run data used to create the ipols, to avoid blow-up of uncertainties with corresponding distortion of fit optimisation.

TODO: asymm version?

professor2.dataio.read_histos(path)

Load histograms from file, into a dict of path -> yoda.Histo[DataBin]

professor2.dataio.read_histos_root(path)

Load histograms from a ROOT file, into a dict of path -> yoda.Histo[DataBin]

professor2.dataio.read_histos_yoda(path)

Load histograms from a YODA-supported file type, into a dict of path -> yoda.Histo[DataBin]

professor2.dataio.read_rundata(dirs, pfname='params.dat', verbosity=1)

Read interpolation anchor point data from a provided set of run directory paths.

Returns a pair of dicts, the first mapping run names (i.e. rundir basenames) to the parameter value list for each run, and the second mapping observable names (i.e. histogram paths) to a run -> histo dict.

## professor2.errors module¶

exception professor2.errors.IpolIOError

Bases: exceptions.Exception

exception professor2.errors.StatError

Bases: exceptions.Exception

## professor2.histos module¶

class professor2.histos.Bin(xmin, xmax, n=None)

Bases: object

A base class for binned data, handling the common x-edge stuff

n
xedges
xmax
xmid
xmin
class professor2.histos.DataBin(xmin, xmax, val=None, errs=None)

A bin containing a data value and its error(s)

err

Get a scalar error value, by averaging if necessary

errs

Get a pair of error values, by construction if necessary

val
class professor2.histos.DataHisto(dbins=None, path=None)

Specialisation of Histo as a container of DataBins

toScatter2D(manpath=None)
class professor2.histos.Histo(bins=None, path=None)

Bases: object

A simple histogram – just a Bin container with an optional path name

bins
nbins
path
class professor2.histos.IpolBin(xmin, xmax, ival=None, ierrs=None)

A bin containing a value interpolation and its error(s)

TODO:
• Provide ierr and ierrs getter/setter pairs cf. err/errs on DataBin? They can’t be averaged (?), so not sure it makes sense...
• Allow ipol’d error handling, with wrapped relative error parameterisation as an option?
der(*params, **vminmax)

Get the derivative according to the parametrisation

err(*params, **eminmax)

Get a single interpolated error, perhaps averaged, for this bin

errs(*params, **eminmax)

Get a pair of interpolated errors for this bin

grad(*params, **vminmax)

Get the gradient according to the parametrisation

has_const_err

Determine whether this bin’s errors are fixed or variable – the latter requires regularisation

ierrs
ival
toDataBin(*params, **veminmax)

Convert this IpolBin to a DataBin with values and errors computed at params, with optional range limits

val(*params, **vminmax)

Get the interpolated value of this bin

class professor2.histos.IpolHisto(ibins=None, path=None)

Specialisation of Histo as a container of IpolBins

toDataHisto(*params)

Convert this IpolBin to a DataBin with values and errors computed at params

## professor2.ipol module¶

professor2.ipol.mk_ipolhisto(histos, runs, paramslist, order, errmode=None, errorder=None)

Make a prof.IpolHisto from a dict of prof.DataHistos and the corresponding runs and params lists, at the given polynomial order.

If errs is non-null, the data histo errors will also be interpolated.

If errmode is None or ‘none’, uncertainties will not be parameterised and will return 0 if queried; ‘mean’ and ‘median’ will use fixed values derived from the anchor points; ‘symm’ will parameterise the average of the + and - errors of each bin at the polynomial order given by errorder. If errorder is None, the same order as for the value parameterisation will be used.

Parameter range scaling will be applied, so a DoParamScaling=true flag will need to be written to the metadata when persisting the resulting IpolHisto.

professor2.ipol.mk_ipolinputs(params)

Make sorted run and parameter lists suitable for passing to prof.Ipol

params is a dict (actually, prefer OrderedDict) of run_names -> param_vals, as returned from read_rundata

## professor2.ipolio module¶

professor2.ipolio.read_binnedipols(ifile, paramlimits=None)

Read binned ipol data back in from ifile.

If the paramlimits argument is non-null, it will be used internally by the Ipol objects to stabilise the SVD calculation. For this to make sense, the persisted ipols must have been created with the same scaling factors. paramlimits should be a 2-tuple of lists for min and max param values respectively.

professor2.ipolio.read_ipolhistos(ifile)

Return both the metadata object and collection of IpolHistos from a binned ipol file

professor2.ipolio.read_ipolmeta(ifile)

Read in meta data from prof-ipol output ‘ifile’

professor2.ipolio.read_simpleipols(ifile, paramlimits=None)

Read ipol data back in from ifile.

If the paramlimits argument is non-null, it will be used internally by the Ipol objects to stabilise the SVD calculation. For this to make sense, the persisted ipols must have been created with the same scaling factors. paramlimits should be a 2-tuple of lists for min and max param values respectively.

## professor2.minimize module¶

professor2.minimize.mk_fitfunc(fname, pnames, globname)

Dynamically make a fit function for the given param names, to be passed to Minuit.

Return a string definition of the function, to be exec’d, and the list of generated internal arg names corresponding to pnames.

## professor2.params module¶

professor2.params.is_inrange(ppoint, minv, maxv)
professor2.params.mk_center(anchors)

Calculate center from all anchor points — needed? Requires knowledge of all anchor points, hmm

professor2.params.mk_maxvals(anchors)
professor2.params.mk_minvals(anchors)
professor2.params.scangrid(*args, **kwargs)

Generator function which returns lists of parameter (name, value) 2-tuples via yields (i.e. in a for-expression).

The arguments are 4-tuples of (name, numpts, low, high) for each parameter; the generator iterations will then visit each of the lattice points in a grid with num points between low..high in each param.

## professor2.paramsio module¶

professor2.paramsio.read_limitsandfixed(fname)

Read a text file e.g. PARAM1 0 1 # interpreted as fixed param PARAM2 0.54444 # interpreted as limits

professor2.paramsio.read_paramsfile(path)

## professor2.sampling module¶

class professor2.sampling.Sampler(low, high, bias=None)

Bases: object

shoot()
professor2.sampling.numCombs(n, k)

n choose k algorithm

professor2.sampling.xrandomUniqueCombinations(items, nchoose, howmany=None)

Generator-like function for n choose k items

## professor2.utils module¶

professor2.utils.mkdict()

Return an OrderedDict if possible, or a normal dict if not.

## professor2.weights module¶

Utilities for matching histo/bin/bin-range paths

professor2.weights.read_pointmatchers(wfile)

Read a file of PointMatcher definition lines, and return an ordered dict of (matcher, string2) pairs, where string2 is the rest of the line.

## Module contents¶

professor2.mk_timestamp()

Time stamp, taken from http://stackoverflow.com/questions/13890935/timestamp-python