Class describing a fit parameter.
Parameters: |
|
---|
float or None
Value of the parameter. Set to None if the parameter is free to float in the fit. Defaults to None.
float
Default value of the parameter.
float
The typical size of variations in this parameter. Defaults to 1.
float or None
Lower bound on the parameter. Set this to None to make the parameter unbounded from below. Defaults to None.
float or None
Upper bound on the parameter. Set this to None to make the parameter unbounded from above. Defaults to None.
callable
Function which generates random values for the parameter. It takes no arguments. This is either the function supplied through the generator keyword or the default setting, if no generator keyword was supplied.
Sets the lower and upper bounds of the parameter.
Parameters: |
|
---|
Class describing constraints on a model’s parameter space.
Parameters: |
|
---|
Compute the constraint function.
Parameters: | q (dict) – Dictionary with all dependent quantities of the model to be constrained. This will be the dict returned by the getDependentQuantities method of the model under consideration. |
---|---|
Returns: | The value c of the constraint. If the equality attribute is False, the constraint is satisfied if c >= 0. If the equaltiy attribute is True, constraint is satisfied if c == 0. |
Return type: | float |
Abstract class describing contributions to the chi-square function.
Parameters: | active (bool, optional) – If set to False the contribution is |
---|
bool
If set to False the contribution is ignored. Defaults
Compute the chi-square contribution.
Note
Derived classes must implement this. The relation between the likelihood function f and the chi-square function chisq (represented by this method) is:
f(q, x) = exp(-chisq(q,x)/2)
The integral of f over x for fixed q must be 1. Derived classes must ensure that this is the case.
Parameters: |
|
---|---|
Returns: | The value of the chi-square function for the specified parameters q and observables x. |
Return type: | float |
Obtain Minimum of the chi-square contribution in observable space.
Note
Derived classes must implement this.
Parameters: | q (dict) – Dictionary holding the model parameters and dependent quantites (as returned by getDependentQuantites). |
---|---|
Returns: | A dictionary describing the position of the minimum of the chi-square contribution in observable space for fixed parameters q. Valid keys of x0 are the names of the observables constrained by this contribution, as returned by the getObservableNames method. |
Obtain the observables which the chi-square contribution constrains.
Note
Derived classes must implement this.
Obtain the quadratic form on observable space.
Note
Derived classes must implement this.
Parameters: | q (dict) – Dictionary holding the model parameters and dependent quantites (as returned by getDependentQuantites). |
---|---|
Returns: | A dictionary whose entries are of the form (i,j) : Qij, where i and j are names of observables which are constrained by this contribution (i.e. elements of the list returned by the getObservableNames method). Qij is the corresponding entry in the observable space matrix. Only non-zero entries must be included in the dictionary. The matrix should be symmetric. For each pair (i,j) with i != j the pair (j,i) should also be a valid key and the associated value should also be Qij. |
Return the smallest possible chi-square value.
Parameters: | x (dict) – Dictionary containing the (observed) values of the observables |
---|
Describes a gaussian contribution with fixed standard deviation.
Parameters: |
|
---|
str
Name of the constrained observable.
float
The standard deviation of the gaussian.
str or None
The name of the nuisance parameter describing the systematic error. Defaults to None, which means that there is no systematic error.
str
Name of the mean value of obs, as it appears in the dictionary returned by the model’s getDependentQuantities method. Defaults to obs.
Describes the contribution of several correlated gaussian observables.
Parameters: |
|
---|---|
Raises: | ValueError – If the correlations specified in cor are invalid. |
Base class for describing a model.
dict
Specifies the independent parameters of the model. The keys must be strings. The values must be Parameter instances.
dict
Specifies the ‘measured’ values of the observables. The keys must be strings. The values must be floats.
dict
Contains the constraints imposed on the model’s parameter space. The keys must be strings. The values must be instances of Constraint.
dict
Contains the contributions of the chi-square function. The keys must be strings. The values must be instances of ChiSquareContribution.
set of str
Names of the CSCs which are associated to nuisance parameters.
Activate all chi-square contributions.
Parameters: | ignorenp (bool, optional) – If True, settings for chi-square contributions from nuisance parameters are not altered. Defaults to True. |
---|
Activate all constraints.
Activate given set of chi-square contributions.
Parameters: | *args (str) – Names of the chi-square contributions to activate. |
---|
Activate given set of constraints.
Activate given set of chi-square contributions, deactivate all others.
Parameters: |
|
---|
Activate given set of constraints, deactivate all others.
Add a constraint on a model’s parameter space.
Parameters: |
|
---|
Add a correlated Gaussian contribution to the chi-square function.
Parameters: |
|
---|---|
Raises: | NameError – Raised when name is already used in the csc dict or any of the observable names in the obs argument are mentioned twice or already exist as keys in the obs attribute. It is also raised when a correlation coefficient is mentioned twice in the cor argument. |
Add a correlated Gaussian nuisance parameters to the model.
This adds several properly initialised Parameter instances to the par dict and a properly initialised CorrelatedGaussianCST instance to the csc dict.
Parameters: |
|
---|
Add a gaussian contribution to the chi-square function.
Parameters: |
|
---|---|
Raises: | NameError – Raised when name is already used in the csc or obs dicts. |
Add a nuisance parameter with a gaussian error to the model.
This adds a properly initialised Parameter instance to the par dict and a properly initialised GaussianCSC instance to the csc dict.
Parameters: |
|
---|
Add a parameter to the model.
Parameters: | name – Unique string which identifies the parameter. |
---|
Add a nuisance parameter with a systematic error to the model.
Parameters: |
|
---|
Compute the chi-square value for given parameters and observables.
Parameters: |
|
---|---|
Returns: | The chi-square value for parameters p and observables obs. |
Return type: | float |
Return a deep copy of the model.
Compute the Delta chi-square value for given parameters and observables.
Parameters: |
|
---|---|
Returns: | The chi-square value for parameters p and observables obs. |
Return type: | float |
Deactivate all chi-square contributions.
Parameters: | ignorenp (bool, optional) – If True, settings for chi-square contributions from nuisance parameters are not altered. Defaults to True. |
---|
Deactivate all constraints.
Deactivate given set of chi-square contributions.
Parameters: | *args (str) – Names of the chi-square contributions to deactivate. |
---|
Activate given set of chi-square contributions.
Deactivate given set of chi-square contributions, activate all others.
Parameters: |
|
---|
Deactivate given set of constraints, activate all others.
Fix model parameters.
Parameters: | *args (str or list of str or dict) – Parameters to fix. For string arguments or lists of strings the corresponding parameter(s) are fixed to their default values. |
---|
Generate a random point in parameter space.
Returns: | A dictionary of the randomly generated parameters. Fixed parameters are included in the dictionary and will have their fixed values. |
---|
Obtain Minimum of the chi-square function in observable space.
Parameters: | q (dict) – Dictionary holding the model parameters and dependent quantites (as returned by getDependentQuantites). |
---|---|
Returns: | A dictionary describing the position of the minimum of the chi-square function in observable space for fixed parameters q. Valid keys are the names of the observables constrained by the chi-square function, as returned by the getObservableNames method. |
Compute the chi-square value from dependent quantities.
This function computes the chi-square value by calling the getChiSquare methods of all active ChiSquareContribution objects in the csc member and adding up the results.
Parameters: |
|
---|---|
Returns: | The value of the chi-square function. |
Return type: | float |
Compute the amount of constraint violation.
Note
This function returns the sum of the squares of the constraint functions for all violated constraints
Parameters: | q (dict) – Contains the parameters and dependent quantities, as returned by the getDependentQuantities method. |
---|
Compute the constraint functions.
Parameters: | q (dict) – Contains the parameters and dependent quantities, as returned by the getDependentQuantities method. |
---|---|
Returns: | A dictionary containing the values of the active constraint functions. The keys are a subset of those found in the con member. The values are floats. |
Obtain a dictionary with the default values of all model parameters.
Compute the Delta chi-square value from dependent quantities.
This function computes the chi-square value minus the absolute lower bound on the chi-square value by calling the getChiSquare and min methods of all active ChiSquareContribution objects in the csc member and adding up the results.
Parameters: |
|
---|---|
Returns: | The value of the chi-square function. |
Return type: | float |
Compute all quantities depending on the model parameters.
Parameters: | p (dict) – Contains the values of the model parameters. The keys must be the same as those of the par member. The values must be floats. |
---|---|
Returns: | A dictionary containing the parameters from p and all quantities which depend on them. The keys are strings and the values are floats. |
Note
The default implementation returns a dictionary with the full set of model parameters, using default values for parameters not specified in p and overriding the values of fixed parameters. Derived classes should add all dependent quantities to the dictionary. Instances of ChiSquareContribution and Constraint will use the dictionary returned by this method to compute the chi-square contributions and the values of the constraint functions, so all quantities needed for these computations should be included. For instances of GaussianCSC this means including the mean value of the corresponding observable. You may use the same string identifier for the observable and the mean.
Obtain a dictionary of the fixed parameters and their values.
Returns: | A dictionary containing the names and values of the parameters which are fixed. |
---|
Obtain the names of the parameters floating in the fit.
Returns: | A list of strings containing the names of the parameters which are free to float in the fit (possibly with lower or upper bounds). |
---|
Obtain the names of the observables predicted by the model.
Returns: | A list of strings containing the names of the observables predicted by the model. |
---|
Note
This list is compiled by calling the getObservableNames method of all elements of the csc attribute and has nothing to do with the keys found in the obs attribute.
Obtain the quadratic form on observable space.
Note
The quadratic form is obtained by calling the getQuadraticForm method of all active chi-square contributions and adding up the results.
Parameters: | q (dict) – Dictionary holding the model parameters and dependent quantites (as returned by getDependentQuantites). |
---|---|
Returns: | A dictionary whose entries are are of the form (i,j) : Qij, where i and j are names of observables which are constrained by the chi-square function (i.e. elements of the list returned by the getObservableNames method). Qij is the corresponding entry in the observable space matrix. Zero entries may be omitted in the dictionary. The matrix is symmetric. |
Release model parameters (allowing them to float in a fit).
Parameters: | *args (str or list of str) – Names of the parameters to release |
---|
Stores the results of a localFit call.
Note
For each keyword argument there is an attribute with the same name. All keyword arguments default to None.
Parameters: |
|
---|
x.__ge__(y) <==> x>=y
x.__gt__(y) <==> x>y
x.__le__(y) <==> x<=y
Return a deep copy.
Sample a model’s parameter space and minimise the chi-square.
Parameters: |
|
---|
Model instance
Associated Model instance.
int
Same as tries keyword argument.
int
Same as retries keyword argument.
float
Same as cvmargin keyword argument.
float
Same as maxcv keyword argument.
str
Same as solver keyword argument.
dict
Same as solvercfg keyword argument.
dict
Same as obs keyword argument.
int
Same as neighbours keyword argument.
float
Same as temperature keyword argument.
float
Same as penalty keyword argument.
Return an iterator over the stored points.
Yields: |
|
---|
Clear the data collected with sample or evolve.
Compute distance between two points in observable space.
Returns: | (float): Distance between x and y. |
---|
Evolve current population towards a more homogenous distribution in observable space.
Parameters: |
|
---|
Iterate over collected points, starting with points nearest to x.
Parameters: | x (dict) – A point in observable space. |
---|---|
Yields: |
|
Find the global minimum of a model’s chi-square function.
Parameters: |
|
---|---|
Returns: | A FitResult instance with the result of the successful local minimization that found the smallest chi-square. |
Find nearest neighbour to a point in observable space.
Parameters: | x (dict) – Point in observable space. |
---|
Find n nearest neighbours to a point in observable space.
Parameters: |
|
---|
Return an iterator over the stored points in observable space.
Return an iterator over the stored points in parameter space.
Sample the model’s parameter space.
Parameters: |
|
---|
Update information about the sample points.
Note
Call this after changing the obs, neighbours, temperature or penalty attributes or after changing the associated Model object.
Parameters: | par (dict, optional) – Reference values for the model parameters. They are used to determine a metric on observable space (by calling model.getQuadraticForm). For observables not listed in par the values from model.getDefaultParameters() are used. Defaults to the empty dict. |
---|
Do a local minimization of a model’s chi-square function.
Parameters: |
|
---|---|
Returns: | An instance of FitResult with the results of the fit. |
Computes the p-value from the chi-square value.
Parameters: |
|
---|---|
Returns: | The p-value corresponding to the chi-square value chisq, using Wilks’ theorem with ndof degrees of freedom. |
Return type: | float |
Computes the chi-square value from the p-value.
Parameters: |
|
---|---|
Returns: | The chi-square value corresponding to the p-value p, using Wilks’ theorem with ndof degrees of freedom. |
Return type: | float |
Computes the Z-value from the p-value.
Note
The Z-value is often referred to as the ‘number of standard deviations’ or ‘number of sigmas’. myFitter uses two-sided Z-values which are related to the p-value by p = 1 - Erf(Z/sqrt(2))
Parameters: | p (float) – The p-value. |
---|---|
Returns: | The Z-value corresponding to the p-value p. |
Return type: | float |
Computes the p-value from the Z-value.
Note
The Z-value is often referred to as the ‘number of standard deviations’ or ‘number of sigmas’. myFitter uses two-sided Z-values which are related to the p-value by p = 1 - Erf(Z/sqrt(2))
Parameters: | z (float) – The Z-value. |
---|---|
Returns: | The p-value corresponding to the Z-value z. |
Return type: | float |
Computes the Z-value from the chi-square value.
Note
The Z-value is often referred to as the ‘number of standard deviations’ or ‘number of sigmas’. myFitter uses two-sided Z-values which are related to the p-value by p = 1 - Erf(Z/sqrt(2))
Parameters: |
|
---|---|
Returns: | The Z-value corresponding to the chi-square value chisq, using Wilks’ theorem with ndof degrees of freedom. |
Return type: | float |
Computes the chi-square value from the Z-value.
Note
The Z-value is often referred to as the ‘number of standard deviations’ or ‘number of sigmas’. myFitter uses two-sided Z-values which are related to the p-value by p = 1 - Erf(Z/sqrt(2))
Parameters: |
|
---|---|
Returns: | The chi-square value corresponding to the Z-value z, using Wilks’ theorem with ndof degrees of freedom. |
Return type: | float |
Compute the profile likelihood on a one-dimensional space.
Note
When the profile likelihood function is to be computed on a 1D grid the stability of the optimisations can be significantly improved by using the best-fit parameters of neighbouring grid points as starting points for local optimisations. The Profiler1D and Profiler2D classes implement this method for one and two-dimensional scans.
For difficult optimisation problems you may need rather detailed control over the procedure for finding the global minima. In this case you can derive a class from Profiler1D and override the fit() method.
The variable in which the profile likelihood is computed can be an arbitrary dependent quantity (not necessarily a model parameter). For a dependent quantity which is not a model parameter a constraint is (temporarily) added to the model. The name of this constraint is '__xscan__'. You should therefore avoid using this name for your own constraints.
Parameters: |
|
---|
Minimise the chi-square for a single grid point.
Note
Derived classes can override this function to implement specific methods for global optimisation. The function should fix the scan variable to xval (using fix()), do local optimisations with all the starting points listed in start, and perform an additional global optimisation if and only if sample is True. The default behaviour is to randomly sample a number of points set by the nsamples attribute and then try a number of local optimisations set by tries.
Parameters: |
|
---|
Fix the variable of the profile likelihood.
Note
If the variable of the profile likelihood is a model parameter it is fixed with myFitter.Model.fix(). Otherwise the bound member of the corresponding constraint is adjusted. You will typically use this function in a derived class when you override the fit() method.
Parameters: | x (float) – Values of the variables. |
---|
Compute the profile likelihood on a specified grid.
Parameters: |
|
---|
Compute the profile likelihood on a two-dimensional space.
Note
When the profile likelihood function is to be computed on a 2D grid the stability of the optimisations can be significantly improved by using the best-fit parameters of neighbouring grid points as starting points for local optimisations. The Profiler1D and Profiler2D classes implement this method for one and two-dimensional scans.
For difficult optimisation problems you may need rather detailed control over the procedure for finding the global minima. In this case you can derive a class from Profile2D and override the fit() method.
The two variables in which the profile likelihood is computed can be arbitrary dependent quantities (not only model parameters). For dependent quantities which are not model parameters a constraint is (temporarily) added to the model. The names of these constraints are '__xscan__' and '__yscan__'. You should therefore avoid using these names for your own constraints.
Parameters: |
|
---|
Minimise the chi-square for a single grid point.
Note
Derived classes can override this function to implement specific methods for global optimisation. The function should fix the scan variables to xval and yval, respectively (using fix()), do local optimisations with all the starting points listed in start, and perform an additional global optimisation if and only if sample is True. The default behaviour is to randomly sample a number of points set by the nsamples attribute and then try a number of local optimisations set by tries.
Parameters: |
|
---|
Fix the variables of the profile likelihood.
Note
If the variables of the profile likelihood are model parameters they are fixed with myFitter.Model.fix(). Otherwise the bound members of the corresponding constraints are adjusted. You will typically use this function in a derived class when you override the myFitter.Profiler2D.fit() method.
Compute the profile likelihood on a specified grid.
Parameters: |
|
---|
Represents a gaussian random variate with a mean and standard deviation.
Parameters: |
|
---|
float
mean of the gaussian variate.
float
standard deviation of the gaussian variate.
Note
GVar objects support addition, subtraction, multiplication and division with floats or other GVar objects. In the latter case errors are combined in quadrature.
Represents one-dimensional histograms.
Parameters: |
|
---|
numpy array
list of central x-values of the histogram bins.
numpy array
list of bin boundaries in x direction.
numpy array
data members (z-values) of the histogram.
Note
Histogram1D supports element-wise addition, subtraction, multiplication, and division with other Histogram1D instances as long as their xvals, yvals, xbins and ybins members are exactly equal. Addition, subtraction, multiplication or division by a constant value for bins is also supported.
Return the data value of a specific bin
Parameters: | x (float) – An x coordinate. |
---|---|
Returns: | The data value of the bin which contains the coordinate x. |
Raises: | KeyError – The coordinate x is outside the range of the histogram. |
Iterate over the bin centres.
Yields: | x (float) – The x-coordinate of the bin centre. |
---|
Set the data value of a specific bin
Parameters: |
|
---|---|
Raises: | KeyError – The coordinate x is outside the range of the histogram. |
Return the center of the bin to which x belongs.
Return an independent copy of self.
Plot errorbars with matplotlib.
Parameters: |
|
---|
Iterate over all elements of the histogram.
Yields: | tuple – (x, v) where x is the bin center and v the value associated with that bin. |
---|
Return the lower bound of the bin to which x belongs.
Return the largest data member in the histogram.
Note
None values are ignored.
Return the smalles data member in the histogram.
Note
None values are ignored.
Plot the histogram with matplotlib.
Parameters: |
|
---|
Set all data values of the histogram.
Parameters: | h (Histogram1D or object) – If h is a Histogram1D instance the function iterates over all bins of h and sets the corresponding bins of self to their values. Otherwise all bin values of self are set to h. |
---|
Set all bins to the maximum of their current value and h.
Parameters: | h (Histogram1D or object) – If h is a Histogram1D instance the function iterates over all bins of h and sets the corresponding bins of self to the maximum of the two values. Otherwise all bins of self are set to the maximum of their current value and h. |
---|
Set all bins to the minimum of their current value and h.
Parameters: | h (Histogram1D or object) – If h is a Histogram1D instance the function iterates over all bins of h and sets the corresponding bins of self to the minimum of the two values. Otherwise all bins of self are set to the minimum of their current value and h. |
---|
Set x limits of the current plot.
Parameters: | axes (matplotlib.axes.Axes or None) – Axes object whose limits are to be set. Uses matplotlib.pyplot.gca() if None. Defaults to None. |
---|
Return the upper bound of the bin to which x belongs.
Represents two-dimensional histograms.
Parameters: |
|
---|
numpy array
list of central x-values of the histogram bins.
numpy array
list of central y-values of the histogram bins.
numpy array
list of bin boundaries in x direction.
numpy array
list of bin boundaries in y direction.
numpy array
data members (z-values) of the histogram. The first index corresponds to the x-axis.
Note
Histogram2D supports element-wise addition, subtraction, multiplication, and division with other Histogram2D instances as long as their xvals, yvals, xbins and ybins members are exactly equal. Addition, subtraction, multiplication or division by a constant value for bins is also supported.
Return the data value of a specific bin
Parameters: | xy (tuple) – A pair of coordinates. |
---|---|
Returns: | The data value of the bin which contains the coordinates xy. |
Raises: | KeyError – The coordinates xy are outside the range of the histogram. |
Iterate over the bin centres.
Yields: |
|
---|
Set the data value of a specific bin
Parameters: |
|
---|---|
Raises: | KeyError – The coordinates xy are outside the range of the histogram. |
Return the center of the bin to which (x,y) belongs.
Draw contour lines with matplotlib
Parameters: |
|
---|
Draw filled contours with matplotlib
Parameters: |
|
---|
Return an independent copy of self.
Iterate over all elements of the histogram.
Yields: | tuple – ((x, y), v) where (x, y) is the bin center and v the value associated with that bin. |
---|
Return the lower left corner of the bin to which (x,y) belongs.
Return the largest data member in the histogram.
Note
None values are ignored.
Return the smallst data member in the histogram.
Note
None values are ignored.
Draw a colored mesh with matplotlib
Parameters: |
|
---|
Set all data values of the histogram.
Parameters: | h (Histogram2D or object) – If h is a Histogram2D instance the function iterates over all bins of h and sets the corresponding bins of self to their values. Otherwise all bin values of self are set to h. |
---|
Set all bins to the maximum of their current value and h.
Parameters: | h (Histogram2D or object) – If h is a Histogram2D instance the function iterates over all bins of h and sets the corresponding bins of self to the maximum of the two values. Otherwise all bins of self are set to the maximum of their current value and h. |
---|
Set all bins to the minimum of their current value and h.
Parameters: | h (Histogram2D or object) – If h is a Histogram2D instance the function iterates over all bins of h and sets the corresponding bins of self to the minimum of the two values. Otherwise all bins of self are set to the minimum of their current value and h. |
---|
Return the upper right corner of the bin to which (x,y) belongs.
Compute the cumulated distribution.
Parameters: |
|
---|---|
Returns: | The cumulated histogram. |
Return type: | Histogram1D |
Note
If hc = cumulated(h, upper=False, const=c) then hc.data[i] = sum(h.data[:i+1]) + c for all i in range(len(h.data)). If hc = cumulated(h, upper=True, const=c) then hc.data[i] = sum(h.data[i:]) + c for all i in range(len(h.data)).
Divide all bin values by the bin width (Histogram1D) or bin area (Histogram2D).
Parameters: | h (Histogram1D or Histogram2D) – the histogram to convert. h is not modified. |
---|---|
Returns: | Histogram1D or Histogram2D: the converted histogram. |
Summarizes the results of a vegas integration.
Parameters: | itnres (list of GVar, optional) – list of GVar objects (or anything that has attributes ‘mean’ and ‘sdev’) corresponding to the results of individual iterations. Defaults to an empty list. |
---|
mean value of weighted average
standard deviation of weighted average
chi-square value of the results of individual iterations
same as itnres keyword argument.
Note
You can join several IntegrationResult instances by adding them. Here is an example which updates and IntegrationResult result after each iteration and prints information about the current state of the integration:
f = ...
integ = Integrator(...)
results = IntegrationResult()
print results.hdr()
for i in range(10):
results += integ(f, nitn=1, neval=500)
print results.info()
Return an independent copy.
Remove the results of the first n iterations.
Parameters: | n (int) – number of iterations to remove. |
---|
Return the header for a running summary of the integration as a string.
Return information about the last iteration and the current average as a string.
Note
Use together with hdr().
Return an array of empty IntegrationResult instances.
Parameters: | n – number of elements of the array. |
---|
Simple wrapper around vegas.Integrator.
Parameters: |
|
---|
Carries out the integration.
Parameters: |
|
---|---|
Returns: | An object holding the results of the iterations and their weighted average. If the integrand returns a list or array the return value is a numpy array of IntegrationResult objects. |
Return type: | IntegrationResult |
Change or read configuration options.
Note
This is essentially the same as the vegas.Integrator.set() method. The configuration dict contains an additional keywords 'parallel', 'drop', and 'log'.
Parameters: | **kwargs (optional) – Configuration options to set. All keywords accepted by vegas.Integator.set() as well as parallel, drop, and log are valid. |
---|---|
Returns: | The old configuration. |
Return type: | dict |
Fill histograms with data.
Parameters: |
|
---|
Note
The function f must be an integrand function. It should take a single numpy array x as argument and return an array whose first element is the function value of the integrand. The other elements can be ‘binned’. The *hist arguments must be of the form (j, h) where h is a Histogram1D or Histogram2D instance and j can be a callable object, a tuple of integers or an integer.
If h is a Histogram1D instance and j is an integer each bin of h with boundaries a and b will be filled with a GVar object holding the estimate of the integral of f(x)[0] over the set defined by a <= f(x)[j] < b. Alternatively j can be a tuple of one integer. If j is a callable object and h a Histogram1D instance the integration domain for each bin is defined by a <= j(x, f(x)) < b.
If h is a Histogram2D instance and j is a tuple of two integers each bin of h with x-boundaries ax and bx and y-boundaries ay and by will contain an estimate of the integral of f(x)[0] over the domain with ax <= f(x)[j[0]] < bx and ay <= f(x)[j[1]] < by. If j is a callable it should return a tuple of two numbers and the integration domain is defined by ax <= j(x, f(x))[0] < bx and ay <= j(x, f(x))[1] < by.
Returns: | The value (and error) of the integral. |
---|---|
Return type: | GVar |
Generate random points.
Parameters: |
|
---|---|
Yields: |
|
Integrand function for computing p-values in LRTs.
Note
Pass instances of LRTIntegrand to myFitter.ToySimulator.__call__() to compute the p-values numerically.
Parameters: |
|
---|
Fitter
Same as fitter0 argument.
Fitter
Same as fitter1 argument.
float or None
Same as dchisq argument.
bool
Same as nested argument.
int
Same as verbose argument.
int
Number of integrand evaluations (since last call to myFitter.LRTIntegrand.reset()).
int
Number of failed integrand evaluations (since last call to myFitter.LRTIntegrand.reset()).
Evaluate the integrand.
Parameters: | x (dict) – The point in observable space. |
---|---|
Returns: | numpy array of 2 floats: The second element is the Delta chi-square value for x. The first element is 0 if this value is smaller than the value of dchisq set in the constructor or if one of the fits failed to find a feasible solution. In all other cases the first element is 1. |
Class for running toy simulations and computing p-values.
Note
ToySimulator is a subclass of Integrator. It can use a “smart” sampling method which is taylored to p-value computations in (nested or non-nested) LRTs. To do this it requires additional information about the alternative hypothesis and the Delta chi-square. If you do not provide this information ToySimulator uses standard sampling (i.e. generates points distributed according to the PDF associated with your null hypothesis).
Parameters: |
|
---|
Integrate a function on observable space.
Parameters: |
|
---|
Fill histograms with data.
Parameters: |
|
---|
Note
The function f must be function on observable space. It should take a dict x representing the point in observable space as argument and return an array whose first element is the function value of the integrand. The other elements can be ‘binned’. The *hist arguments must be of the form (j, h) where h is a Histogram1D or Histogram2D instance and j can be a callable object, a tuple of integers or an integer.
If h is a Histogram1D instance and j is an integer each bin of h with boundaries a and b will be filled with a GVar object holding the estimate of the integral of f(x)[0] over the set defined by a <= f(x)[j] < b. Alternatively j can be a tuple of one integer. If j is a callable object and h a Histogram1D instance the integration domain for each bin is defined by a <= j(x, f(x)) < b.
If h is a Histogram2D instance and j is a tuple of two integers each bin of h with x-boundaries ax and bx and y-boundaries ay and by will contain an estimate of the integral of f(x)[0] over the domain with ax <= f(x)[j[0]] < bx and ay <= f(x)[j[1]] < by. If j is a callable it should return a tuple of two numbers and the integration domain is defined by ax <= j(x, f(x))[0] < bx and ay <= j(x, f(x))[1] < by.
Returns: | The value (and error) of the integral. |
---|---|
Return type: | GVar |
Generate random points in observable space.
Note
This function returns an iterator which generates points in observable space distributed according to a Gaussian approximation of the PDF of model0 with parameters par0 (both set in the constructor). If model0 has only Gaussian observables the approximation is exact.
Parameters: | **kwargs (optional) – Keyword arguments to be passed to Integrator.random. The most important one is neval, which defines the maximal number of points yielded by the iterator. |
---|---|
Yields: |
|
Class for parallel function evaluation.
Note
ParallelFunction objects are callable and accept a numpy array or list of python objects as argument. They parallelise the task of applying a certain function to each element of the array. Process communication is done via files and the parallel jobs can be run on different nodes of a computing cluster.
Parameters: |
|
---|
Decorator for parallelising a function.
Note
Use as follows:
@parallel(...)
def myfunc(x):
...
The arguments for parallel are the same as for ParallelFunction, but without the initial argument f. The defined function is parallelised and should only take a single argument.
Base class for runners (classes that control individual parallel jobs).
Parameters: |
|
---|
bool
True if the job is currently running.
bool
True if the job has finished (normally or abnormally).
str
Same as keyword argument name.
int
Same as keyword argument batchid.
str
Same as keyword argument workdir.
str
Same as keyword argument script.
list of str
Same as keyword argument args.
str
Same as keyword argument stdout.
str
Same as keyword argument stderr.
str
Same as keyword argument pyexec.
Cancel the job.
Note
Derived classes must implement this. The job should be cancelled, self.running should be set to False and self.finished to True.
Update the job status.
Note
Derived classes must implement this. If the job is pending (not started yet) it should set self.running and self.finished to False. If the job is currently running it should set self.running to True and self.finished to False. If the job has finished (normally or abnormally) it should set self.running to False and self.finished to True.
Run job as independent process on local machine.
Submit job to the SLURM batch system.