alea.models package

Submodules

alea.models.blueice_extended_model module

class alea.models.blueice_extended_model.BlueiceExtendedModel(parameter_definition: dict, likelihood_config: dict, **kwargs)[source]

Bases: StatisticalModel

A statistical model based on blueice likelihoods.

This class extends the StatisticalModel class and provides methods for generating data and computing likelihoods based on blueice.

parameters

Parameters object containing the parameters of the model.

Type

Parameters

data

Data of the statistical model.

Type

dict

is_data_set

Whether data is set.

Type

bool

_likelihood

A blueice LogLikelihoodSum instance.

Type

LogLikelihoodSum

likelihood_names

List of likelihood names.

Type

list

livetime_parameter_names

List of the name of the livetime of each term, None if not specified

Type

list

data_generators

List of data generators for each likelihood term.

Type

list

Parameters
  • parameter_definition (dict) – A dictionary defining the model parameters.

  • likelihood_config (dict) – A dictionary defining the likelihood.

Todo

analysis_space could be inferred from the data (assert that all sources have the same analysis_space)

__init__(parameter_definition: dict, likelihood_config: dict, **kwargs)[source]

Initializes the statistical model.

Parameters
  • parameter_definition (dict) – A dictionary defining the model parameters.

  • likelihood_config (dict) – A dictionary defining the likelihood.

_build_data_generators() list[source]

Build data generators for all likelihood terms.

Returns

List of data generators for each likelihood term.

Return type

list

Todo

Also implement data generator for ancillary ll term.

_build_ll_from_config(likelihood_config: dict, template_path: Optional[str] = None) LogLikelihoodSum[source]

Iterate through all likelihood terms and build blueice likelihood instances.

Parameters

likelihood_config (dict) – A dictionary defining the likelihood.

Returns

A blueice LogLikelihoodSum instance.

Return type

LogLikelihoodSum

_generate_ancillary(**generate_values) dict[source]

Generate data for the ancillary likelihood.

Keyword Arguments

generate_values (dict) – A dictionary of parameter values.

Returns

A numpy structured array of ancillary measurements.

Return type

numpy.array

_generate_data(**generate_values) dict[source]

Generate data for all likelihood terms and ancillary likelihood.

Keyword Arguments

generate_values (dict) – A dictionary of parameter values.

Returns

A dict of data-sets, with key of the likelihood term name, “ancillary” and “generate_values”.

Return type

dict

_generate_science_data(**generate_values) dict[source]

Generate the science data for all likelihood terms except the ancillary likelihood.

_process_blueice_config(config, template_folder_list)[source]

Process the blueice config from config.

_set_default_ptype()[source]

Check if all parameters have a ptype that is in the list of allowed ptypes.

If no ptype is specified, set the default ptype “needs_reinit”.

_set_efficiency(source: dict, ll)[source]

Set the efficiency of a source in the blueice ll.

Parameters
  • source (dict) – A dictionary defining the source.

  • ll (LogLikelihood) – A blueice LogLikelihood instance.

Raises

ValueError – If the efficiency_name is not specified in the source.

property all_source_names: list

Return a set of possible source names from all likelihood terms.

Parameters

likelihood_name (str) – Name of the likelihood.

Returns

set of source names.

Return type

set

property data: Union[dict, list]

Return the data of the statistical model.

classmethod from_config(config_file_path: str, **kwargs) BlueiceExtendedModel[source]

Initializes the statistical model from a yaml config file.

Parameters

config_file_path (str) – Path to the yaml config file.

Returns

Statistical model.

Return type

BlueiceExtendedModel

get_expectation_values(per_likelihood_term=False, **kwargs) dict[source]

Return total expectation values (summed over all likelihood terms with the same name) given a number of named parameters (kwargs)

Parameters
  • per_likelihood_term (bool) – If True, return expectation values per likelihood term. Otherwise, sum each source over all likelihood terms.

  • kwargs – Named parameters

Returns

Dictionary of expectation values. If per_likelihood_term is True, the dictionary

has the form {likelihood_name: {source_name: expectation_value, …}, …}.

Return type

dict

Todo

Make a self.likelihood_temrs dict with the likelihood names as keys and the corresponding likelihood terms as values.

get_source_histograms(likelihood_name: str, expected_events=False, **kwargs) dict[source]

Return the pdfs or histograms of all sources for a given likelihood term.

Parameters
  • likelihood_name (str) – Name of the likelihood term.

  • expected_events (bool) – If True, return the histograms containing the number of expected events.

  • kwargs – Named parameters.

Returns

Dictionary containing a multihist object for each source.

Return type

dict

get_source_name_list(likelihood_name: str) list[source]

Return a list of source names for a given likelihood term. The order is the same as used in the source column of the data, so this can be used to map the indices provided in the data to a source name.

Parameters

likelihood_name (str) – Name of the likelihood.

Returns

List of source names.

Return type

list

property likelihood_list: List

Return a list of likelihood terms.

property likelihood_parameters: List

Return a list of likelihood parameters.

store_data(file_name, data_list, data_name_list=None, metadata=None)[source]

Store data in a file.

Append the generate_values to the data_name_list.

store_real_data(file_name: str, real_data_list: list, metadata=None)[source]

Store real data in a file with toydata format.

Parameters
  • file_name (str) – Name of the file.

  • real_data_list (list) – List of np.array of real data.

class alea.models.blueice_extended_model.CustomAncillaryLikelihood(parameters: Parameters)[source]

Bases: LogAncillaryLikelihood

Custom ancillary likelihood that can be used to add constraint terms for parameters of the likelihood.

parameters

Parameters object containing the parameters to be constrained.

Type

Parameters

constraint_functions

Dict of constraint functions for all ancillary parameters.

Type

dict

__init__(parameters: Parameters)[source]

Initialize the CustomAncillaryLikelihood.

_get_constraint_functions(**generate_values) dict[source]

Get callable constraint functions for all ancillary parameters.

Keyword Arguments

generate_values (dict) – A dictionary of parameter values.

Returns

Dict of constraint functions for all ancillary parameters.

Return type

dict

Todo

Implement str-type uncertainties.

ancillary_sum(evaluate_at: dict) float[source]

Return the sum of all constraint terms.

Parameters

evaluate_at (dict) – Values of the ancillary measurements.

Returns

Sum of all constraint terms.

Return type

float

property constraint_terms: dict

Dict of all constraint terms (logpdf of constraint functions) of the ancillary likelihood.

Returns

Dict of all constraint terms function.

Return type

dict

set_data(d: array)[source]

Set the data of the ancillary likelihood (ancillary measurements).

Parameters

d (numpy.array) – Data of ancillary measurements, stored as numpy array.

Module contents