LinearEinsumPredictor

class remu.likelihood.LinearEinsumPredictor(subscripts, coefficients, constants=0.0, weights=1.0, bounds=None, defaults=None, reshape_parameters=None)[source]

Bases: remu.likelihood.Predictor

Predictor calcuating a linear combination of the paramters using np.einsum.

Notes

At least one of bounds, defaults, or reshape_parameters must be provided in order to calculate the expected number of parameters.

The prediction will be calculated using np.einsum using the provided subscripts string. The two operands will be the provided coefficients as well as the parameters of the prediction function call.

The parameters will have the shape [(A,B,...,)+]reshape_parameters, if reshape_parameters is set, or ([A,B,...,]n_parameters) otherwise.

The output of the np.einsum _must_ have the shape ([A,B,...,]n_systematics,[X,Y,...,]Z), no matter whethre the dimensions A, B, ... actually exist.

Examples

This predictor will calculate the product of the parameters with the systematically varied matrices:

>>> M = [ [[1,0], [0,1]], [[0.9, 0], [0, 0.8]] ]
>>> p = LinearEinsumPredictor("ijk,...k->...ij", M, defaults=[1,1])
>>> p([1.0, 2.0])
(array([[1. , 2. ],
    [0.9, 1.6]]),
 array([1., 1.]))

Interpret parameters as matrix and do a matrix multiplication:

>>> M = [ [[1,0], [0,1]], [[0.9, 0], [0, 0.8]] ]
>>> p = LinearEinsumPredictor("ijk,...kl->...ijl", M, reshape_parameters=(2,2))
>>> p([1.0, 2.0, 3.0, 4.0])
(array([[1. , 2. , 3. , 4. ],
    [0.9, 1.8, 2.4, 3.2]]),
 array([1., 1.]))

Do an element-wise multiplication:

>>> M = [ [1, 2, 3, 4] ]
>>> p = LinearEinsumPredictor("ij,...j->...ij", M, reshape_parameters=(4,))
>>> p([1.0, 1.0, 1.0, 1.0])
(array([[1., 2., 3., 4.]]), array([1.]))

Methods

__call__(*args, **kwargs)

See prediction().

check_bounds(parameters)

Check that all parameters are within bounds.

compose(other)

Return a new Predictor that is a composition with other.

fix_parameters(fix_values)

Return a new Predictor with fewer free parameters.

prediction(parameters[, systematics_index])

Turn a set of parameters into a reco prediction.

check_bounds(parameters)

Check that all parameters are within bounds.

compose(other)

Return a new Predictor that is a composition with other.

new_predictor(parameters) = self(other(parameters))
fix_parameters(fix_values)

Return a new Predictor with fewer free parameters.

Parameters
fix_valuesiterable

List of the parameter values that the parameters should be fixed at. The list must be of the same length as the number of parameters of predictor. Any parameters that should remain unfixed should be specified with None or np.nan.

prediction(parameters, systematics_index=slice(None, None, None))[source]

Turn a set of parameters into a reco prediction.

Returns
predictionndarray
weightsndarray