API reference#

This page documents the modules, classes, and functions provided by the probeye package.

probeye.definition#

inverse_problem#

class InverseProblem(name, use_default_logger=True, log_level='INFO', log_file=None, print_header=True)[source]#

Bases: object

This class provides a general framework for defining an inverse problem (more specifically, a parameter estimation problem) without specifying or providing any computational means for solving the problem.

Parameters
  • name (str) – This is the name of the problem and has only descriptive value, for example when working with several inverse problems.

  • use_default_logger (bool) – When True, the logger will be set up with some useful default values. Otherwise, no logger configurations are applied and a logger can be defined outside of the problem definition.

  • log_level (str) – The log-level used by the default logger for printing to std out. This argument is intended for quickly controlling the amount of logging output the user sees on the screen when running probeye.

  • log_file (Optional[str]) – Path to the log-file, if the logging-stream should be printed to file. If None is given, no logging-file will be created.

  • print_header (bool) – If True, a probeye header is logged when an instance of this class is created. Otherwise, the header will not be logged.

add_experiment(name, sensor_data)[source]#

Adds a single experiment to the inverse problem. An experiment is simply a collection of measured data which was produced by one event. The measured data is given in form of a dictionary (sensor_data).

Parameters
  • name (str) – The name of the experiment, e.g. “Exp_20May.12”. If an experiment with a similar name has already been added, it will be overwritten and a warning will be thrown.

  • sensor_data (dict) – The keys are the sensor’s names (for example ‘strain_gauge_1’) and the values are the measured values.

add_forward_model(forward_model, experiments)[source]#

Adds a forward model to the inverse problem. Note that multiple forward models can be added to one problem.

Parameters
  • forward_model (probeye.definition.forward_model.ForwardModelBase) – Defines the forward model. Check out forward_model.py to see a template for the forward model definition. The user will then have to derive his own forward model from that base class. Examples can be found in the package directory tests/integration_tests.

  • experiments (Union[str, list]) – A single string or a list of strings that represents the names of the problem’s experiments that are described by forward_model.

add_likelihood_model(likelihood_model)[source]#

Adds a likelihood model to the inverse problem. Note that a single problem can have multiple likelihood models. It is assumed that all likelihood models of a problem are mutually independent. Note that before adding a likelihood model, all the experiments the likelihood model should refer to must have already been added to the InverseProblem.

Parameters

likelihood_model (probeye.definition.likelihood_model.GaussianLikelihoodModel) – The general likelihood model object, see likelihood.py. This likelihood model is general in that sense, that it is merely descriptive without providing any computational means. The general likelihood model will be translated into a likelihood model with computational means in the solver that will later be used to ‘solve’ the inverse problem.

add_parameter(name, prm_type='not defined', dim=1, domain='(-oo, +oo)', value=None, prior=None, info='No explanation provided', tex=None)[source]#

Adds a parameter (‘const’ or ‘latent’) to the inverse problem. For more information, check out the Parameters.add_parameter method.

Parameters
change_constant(prm_name, new_value)[source]#

Changes the value of a ‘const’-parameter, i.e. a constant parameter of the inverse problem. Note that constants cannot be modified in any other way.

Parameters
  • prm_name (str) – The name of the ‘const’-parameter whose value should be changed.

  • new_value (Union[int, float]) – The new value that prm_name should assume.

change_parameter_info(prm_name, new_info=None, new_tex=None)[source]#

Changes the info-string and/or the tex-string of a given parameter. This task can also be done directly since the ‘info’ and ‘tex’ attributes of the parameters are not protected. However, to do so, one needs to know some of the internal structure. With this function, one does not need to know anything about the internals. So, it is more a convenience function (which however might not be needed very often).

Parameters
  • prm_name (str) – The name of the parameter whose info/tex-string should be changed.

  • new_info (Optional[str]) – The new string for the explanation of parameter prm_name.

  • new_tex (Optional[str]) – The new string for the parameter’s tex-representation.

change_parameter_role(prm_name, value=None, prior=None, domain='(-oo, +oo)')[source]#

Performs the necessary tasks to change a parameter’s role in the problem definition. A parameter’s role can either be changed from ‘const’ to ‘latent’ or from ‘latent’ to ‘const’. Note that parameter roles cannot be modified in any other way.

Parameters
  • prm_name (str) – The name of the parameter whose role should be changed.

  • value (Optional[Union[int, float]]) – If the new role is ‘const’, the corresponding value has to be specified by this argument.

  • prior (Optional[probeye.definition.distribution.ProbabilityDistribution]) – If the new role is ‘latent’, this argument has to be given as a 2-tuple. Check out the explanations in self.add_parameter for more information on this argument.

  • domain (str) – The parameter’s domain (i.e., values it may assume). Note that this argument is only considered for latent parameter, but not for a constant.

change_parameter_type(prm_name, new_type)[source]#

Changes the type of a parameter, i.e., ‘model’, ‘prior’ or ‘likelihood’. Note that parameter types cannot be modified in any other way.

Parameters
  • prm_name (str) – The name of the parameter whose type should be changed.

  • new_type (str) – The new type, either ‘model’, ‘prior’ or ‘likelihood’.

check_parameter_domains(theta)[source]#

Checks whether the given values of the latent parameters are within their specified domains.

Parameters

theta (numpy.ndarray) – A numeric vector or tensor, which contains the current values of all latent parameters.

Returns

  • True if all values given by theta are within their specified domains.

  • Otherwise, False is returned.

Return type

bool

check_problem_consistency()[source]#

Conducts various checks to make sure the problem definition does not contain any inconsistencies.

property constant_prms: List[str]#

Provides constant_prms attribute.

property constant_prms_dict: dict#

Provides constant_prms_dict attribute.

get_experiment_names(forward_model_names=None, sensor_names=None, experiment_names=None)[source]#

Extracts the names of all experiments which refer to a forward model from a given list and/or which contain a set of given sensors. The experiments are extracted from a given set of experiments.

Parameters
  • forward_model_names (Optional[Union[str, List[str]]]) – The names of the forward model the experiments should refer to. This means, to be selected, an experiment must refer to one of those fwd model names.

  • sensor_names (Optional[Union[str, List[str]]]) – The names of the sensors the experiments should should contain. To be selected, an experiment must contain all of the sensors stated in this list.

  • experiment_names (Optional[Union[str, List[str]]]) – The names of the experiments to sub-select from. If None is given, then all experiments of the problem will be used.

Returns

The names of the sub-selected experiments.

Return type

relevant_experiment_names

get_parameters(theta, prm_def)[source]#

Extracts the numeric values for given parameters that have been defined within the inverse problem. The numeric values are extracted either from the latent parameter vector theta or from the constant parameters of the problem.

Parameters
  • theta (numpy.ndarray) – A numeric parameter vector passed to the loglike and logprior method. Which parameters these numbers refer to can be checked by calling the method self.theta_explanation() once the problem is set up.

  • prm_def (dict) – Defines which parameters to extract. The keys of this dictionary are the global parameter names, while the values are the local parameter names. In most cases global and local names will be identical, but sometimes it is convenient to define a local parameter name, e.g. in the forward model.

Returns

Contains <local parameter name> : <(global) parameter value> pairs. If a parameter is scalar, its value will be returned as a float. In case of a vector-valued parameter, its value will be returned as a np.ndarray.

Return type

prms

get_theta_names(tex=False, components=False)[source]#

Returns the parameter names of the latent parameter vector theta in the corresponding order (either in tex- or conventional format).

Parameters
  • tex (bool) – If True, the TeX-names of the parameters will be returned, otherwise the global names as they are used in the code will be returned.

  • components (bool) – If True, parameters with dimension > 1 are returned component-wise; e.g., if ‘alpha’ is a 2D parameter, it will be returned as ‘alpha_1’ and ‘alpha_2’. If False, only ‘alpha’ would be returned.

Returns

List of strings with the parameter names appearing in theta.

Return type

theta_names

info(tablefmt='presto', check_consistency=True, print_header=False, return_string=False)[source]#

Logs an overview of the problem definition and returns the generated string.

Parameters
  • tablefmt (str) – An argument for the tabulate function defining the style of the generated table. Check out tabulate’s documentation for more info.

  • check_consistency (bool) – When True, a consistency check is performed before printing the explanations on theta. When False, this check is skipped.

  • print_header (bool) – When True, the probeye header is printed before printing the problem information. Otherwise, the header is not printed.

  • return_string (bool) – When True, the constructed string is returned. Otherwise it is just logged without it being returned.

Returns

  • The constructed string providing the problem’s definition if ‘return_string’

  • was set to True. Otherwise, None is returned.

Return type

Optional[str]

property latent_prms: List[str]#

Provides latent_prms attribute.

property latent_prms_dims: List[int]#

Provides latent_prms_dims attribute.

property likelihood_prms: List[str]#

Provides likelihood_prms attribute.

property model_prms: List[str]#

Provides model_prms attribute.

property n_constant_prms: int#

Provides n_constant_prms attribute.

property n_latent_prms: int#

Provides n_latent_prms attribute.

property n_latent_prms_dim: int#

Provides n_latent_prms_dim attribute.

property n_likelihood_prms: int#

Provides n_likelihood_prms attribute.

property n_model_prms: int#

Provides n_model_prms attribute.

property n_prior_prms: int#

Provides n_prior_prms attribute.

property n_prms: int#

Provides n_prms attribute.

property prior_prms: List[str]#

Provides prior_prms attribute.

property priors: dict#

Provides the problem’s prior-dictionary which is derived dynamically from the latent parameters in the self.parameters dictionary. The keys are the priors names, while the values are the prior-objects.

property prms: List[str]#

Provides prms attribute.

remove_parameter(prm_name)[source]#

Removes a parameter (‘const’ or ‘latent’) from inverse problem.

Parameters

prm_name (str) – The name of the parameter to be removed.

theta_explanation(check_consistency=True)[source]#

Returns a string describing how the theta-vector, which is the numeric latent parameter vector that is given to the likelihood and prior methods, is interpreted with respect to the problem’s parameters. The printout will tell you which parameter is connected to which index of theta.

Parameters

check_consistency (bool) – When True, a consistency check is performed before printing the explanations on theta. When False, this check is skipped.

Returns

The constructed string.

Return type

s

forward_model#

class ForwardModelBase(name, *args, **kwargs)[source]#

Bases: object

This class serves as a base class for any forward model. When you want to define a specific forward model, you need to derive your own class from this one, and then define the ‘__call__’ method. The latter essentially describes the model function mapping the model input to the output.

Parameters
  • name (str) – The name of the forward model. Must be unique among all forward model’s names within a considered InverseProblem.

  • args – Additional positional arguments that might be passed to the forward model when it is initialized.

  • kwargs – Additional keyword arguments that might be passed to the forward model when it is initialized.

_check_std_definitions()[source]#

Checks if the forward model’s output sensors share a common model error standard deviation parameter. The result is written to self.sensors_share_std_model.

_evaluate_interface()[source]#

Sets the attributes prms_def, prms_dim, input_sensors and output_sensors. This method is called during initialization.

connect_experimental_data_to_sensors(exp_name, sensor_data)[source]#

Connects the experimental data from an experiments to the corresponding sensors of the forward model. Note that sensor-objects are essentially dictionaries, so the connection is established by adding the ‘exp_name’ as key to the respective sensor-(dict)-object with the measurements as the dict-values. This method is called in the solvers before starting an inference routine.

Parameters
  • exp_name (str) – The name of the experiment the ‘sensor_values’ are coming from.

  • sensor_data (dict) – Keys are the sensor names (like “x” or “y”) and values are either floats, integers or numpy-ndarrays representing the measured values.

property input_channel_names: List[str]#

Provides input_channel_names attribute.

property input_sensor: probeye.definition.sensor.Sensor#

Returns the 1st input sensor. Intended for models with only one onf them.

property input_sensor_dict: dict#

Returns dict with input sensor names as keys and sensor objects as values.

property input_sensor_names: List[str]#

Provides input_sensor_names attribute.

interface()[source]#

This method must be overwritten by the user. It is used to explicitly define the forward model’s parameters, input and output sensors. Check out the integration tests to see examples.

property n_output_sensors: int#

Provides number of output_sensors as an attribute.

property output_sensor: probeye.definition.sensor.Sensor#

Returns the 1st output sensor. Intended for models with only one onf them.

property output_sensor_names: List[str]#

Provides input_sensor_names attribute.

prepare_experimental_inputs_and_outputs()[source]#

This method prepares the experimental-data-collection over the forward model’s input and output sensors. This is done in an own method here for efficiency reasons. Without this method, the loops over the input and output sensors would be repeated in each evaluation of the forward model. This method is called in the solvers before starting an inference routine. It sets the two general attributes ‘self.input_from_experiments’ and ‘self.output_from_experiment’.

response(inp)[source]#

Evaluates the model response and provides computed results for all of the model’s output sensors. This method must be overwritten by the user.

Parameters

inp (dict) – Contains both the exp. input data and the model’s parameters. The keys are the names, and the values are their numeric values.

Returns

Contains the model response (value) for each output sensor, referenced by the output sensor’s name (key).

Return type

dict

property sensor_names: List[str]#

Provides a list of all sensor names as an attribute.

likelihood_model#

class GaussianLikelihoodModel(experiment_name, model_error, measurement_error=None, correlation=None)[source]#

Bases: object

This class describes a Gaussian (i.e., normal) likelihood model in general terms. It contains information such as the likelihood model’s latent parameters, its scope with respect to a given experiment, the sensors it considers, error model specifics as well as information on possible correlations to be considered.

Parameters
  • experiment_name (str) – The name of the experiment the likelihood model refers to. Note that each likelihood model refers to exactly one experiment.

  • model_error (str) – Either ‘additive’ or ‘multiplicative’. This argument defines whether an additive or a multiplicative model prediction error should be assumed.

  • measurement_error (Optional[str]) – If True, next to the model error, a normal, zero-mean i.i.d. measurement error is assumed to be present.

  • correlation (Optional[probeye.definition.correlation_model.CorrelationModel]) –

property correlation_variables: list#

Shortens the access of the correlation model’s correlation variables.

determine_output_lengths()[source]#

Sets the self.output_lengths dictionary. This dict contains information on the length of the returned values of the likelihood model’s forward model in the likelihood model’s experiment. A simple example for an uncorrelated case could look like this (note that the ‘:’-character is the key for the full response): {‘:’: {‘total’: 202, ‘increments’: [101, 101], ‘names’: [‘y1’, ‘y2’]}} This is interpreted as follows: for the likelihood’s experiment, the forward model’s output dictionary will eventually be translated into a vector holding 202 values, where the first 101 belong to output sensor ‘y1’ and the following 101 values belong to output sensor. In a correlated case, the created dict will additionally contain the lengths of the correlation variables, e.g.: {‘:’: {‘total’: 12, ‘increments’: [6, 6], ‘names’: [‘y1’, ‘y2’]},

‘t’: {‘total’: 2, ‘increments’: [1, 1], ‘names’: [‘y1’, ‘y2’]}, ‘x’: {‘total’: 12, ‘increments’: [6, 6], ‘names’: [‘y1’, ‘y2’]}}

The ‘t’ and ‘x’ entries are interpreted as the ‘t’-correlation vector having length 2 and the ‘x’-correlation vector having length 12, while the remaining information is interpreted analogously as described before.

parameter#

class ParameterProperties(prm_dict)[source]#

Bases: object

Describes relevant properties of a (‘latent’ or ‘const’) parameter. Objects from this class are associated with the parameter’s name in the dictionary class ‘Parameters’, see above. The use of this class as opposed to a standard dictionary allows convenient auto-completion while coding.

Parameters

prm_dict (dict) – The keys are ‘index’, ‘dim’, ‘type’, ‘role’, ‘prior’, ‘value’, ‘info’ and ‘tex’, while the values are the corresponding values of these properties. See also the explanations in InverseProblem.__init__() for more detailed information.

changed_copy(index=None, dim=None, domain=None, type=None, prior=None, value=None, info=None, tex=None)[source]#

Convenience method that simplifies changing the attributes of a ParameterProperties object based on creating a new instance. The reason for this approach is that some of the attributes are private, and cannot (or at least should not) be changed directly from outside.

See the explanations in InverseProblem.__init__() for more detailed information on the arguments.

Parameters
  • index (Optional[int]) –

  • dim (Optional[int]) –

  • domain (Optional[Union[tuple, List[tuple]]]) –

  • type (Optional[str]) –

  • prior (Optional[Union[list, tuple]]) –

  • value (Optional[Union[int, float, numpy.ndarray]]) –

  • info (Optional[str]) –

  • tex (Optional[str]) –

Return type

probeye.definition.parameter.ParameterProperties

check_consistency()[source]#

Checks the defined attributes in both isolated checks (each attribute is checked without considering others) and cross-checks, where the combination of attributes is checked on consistency.

property dim: int#

Access self._dim from outside via self.dim.

property domain: Union[tuple, list]#

Access self._domain from outside via self.domain.

property index: int#

Access self._index from outside via self.index.

property index_end: int#

Adds a pseudo-attribute self.index_end, which allows a convenient access to the (not-inclusive) end index in the parameter vector.

property is_const: bool#

Adds a pseudo-attribute self.is_const, which allows a convenient check on whether a parameter is constant or not.

property is_latent: bool#

Adds a pseudo-attribute self.is_latent, which allows a convenient check on whether a parameter is latent or not.

property prior: Optional[Union[tuple, list]]#

Access self._prior from outside via self.prior.

property role: str#

Adds a pseudo-attribute self.role, which allows a convenient check on whether a parameter is latent or not.

static translate_domain_string(domain_string)[source]#

Translate a domain string like “(0, 1]” into a list of ScalarInterval objects.

Parameters

domain_string (str) – A string like “(0, 1]” or “[0, 1] [0, 1]” defining the domain of a (possibly vector-valued) parameter.

Returns

List of ScalarInterval objects derived form ‘domain_string’.

Return type

intervals

property type: str#

Access self._type from outside via self.type.

property value: Union[int, float]#

Access self._value from outside via self.value.

class Parameters[source]#

Bases: dict

The main parameter ‘library’. In this dictionary, all of the problem’s parameters are stored. The parameter’s names are the keys, and the associated values are ParameterProperties-objects, see below.

add_parameter(prm_name, prm_type='not defined', dim=1, domain='(-oo, +oo)', value=None, prior=None, info='No explanation provided', tex=None)[source]#

Adds a parameter (‘const’ or ‘latent’) to the Parameters-object. The main functionality of this method is to distinguish between the two types (‘const’ and ‘latent’) and in creating the prior-object and adding the prior-parameters when adding a latent param. to the problem.

Parameters
  • prm_name (str) – The name of the parameter which should be added to the problem.

  • prm_type (str) – Either ‘model’ (for a model parameter), ‘prior’ (for a prior parameter) or ‘likelihood’ (for a likelihood parameter).

  • dim (Optional[int]) – The parameter’s dimension.

  • domain (str) – The parameter’s domain (i.e., values it may assume). Note that this argument is only considered for latent parameter, but not for a constant.

  • value (Optional[Union[int, float, tuple, numpy.ndarray]]) – If the added parameter is a ‘const’-parameter, the corresponding value has to be specified by this argument.

  • prior (Optional[probeye.definition.distribution.ProbabilityDistribution]) – If the added parameter is a ‘latent’-parameter, this argument has to be given as a 2-tuple. The first element (a string) defines the prior-type (will be referenced in inference routines). The 2nd element must be a dictionary stating the prior’s parameters as keys and their numeric values as values or the name of a pre-defined parameter within the problem scope. An example for a normal prior: (‘normal’, {‘loc’: 0.0, ‘scale’: 1.0}). In order to define the prior’s parameters, check out the prior definitions in priors.py.

  • info (str) – Short explanation on the added parameter.

  • tex (Optional[str]) – The TeX version of the parameter’s name, for example r’$eta$’ for a parameter named ‘beta’.

confirm_that_parameter_does_not_exists(prm_name)[source]#

Checks if a parameter, given by its name, exists among the currently defined parameters. An error is raised when the given parameter does already exist.

Parameters

prm_name (str) – A global parameter name.

confirm_that_parameter_exists(prm_name)[source]#

Checks if a parameter, given by its name, exists among the currently defined parameters. An error is raised when the given parameter does not exist yet.

Parameters

prm_name (str) – A global parameter name.

const_parameter_values(tablefmt='presto')[source]#

Returns a string providing the values of the defined ‘const’-parameters.

Parameters

tablefmt (str) – An argument for the tabulate function defining the style of the generated table. Check out tabulate’s documentation for more info.

Returns

This string describes a nice table with the names and values of the constant parameters of the problem.

Return type

prm_string

property constant_prms: List[str]#

Access the names of all ‘const’-parameters as an attribute.

property constant_prms_dict: dict#

Access the names and values of all ‘const’-param. as an attribute.

property latent_prms: List[str]#

Access the names of all ‘latent’-parameters as an attribute.

property latent_prms_dims: List[int]#

Access the individual dimensions of the latent parameters.

property likelihood_prms: List[str]#

Access the names of all ‘likelihood’-parameters as an attribute.

property model_prms: List[str]#

Access the names of all ‘model’-parameters as an attribute.

property n_constant_prms: int#

Access the number of all ‘const’-parameters as an attribute.

property n_latent_prms: int#

Access the number of all ‘latent’-parameters as an attribute.

property n_latent_prms_dim: int#

Access the combined dimension of all latent parameters. This number is the number of elements in the theta vector.

property n_likelihood_prms: int#

Access the number of all ‘likelihood’-parameters as an attribute.

property n_model_prms: int#

Access the number of all ‘model’-parameters as an attribute.

property n_prior_prms: int#

Access the number of all ‘prior’-parameters as an attribute.

property n_prms: int#

Access the number of all parameters as an attribute.

overview(tablefmt='presto')[source]#

Returns a string providing an overview of the defined parameters.

Parameters

tablefmt (str) – An argument for the tabulate function defining the style of the generated table. Check out tabulate’s documentation for more info.

Returns

This string describes a nice table with some essential information on the parameters of the problem.

Return type

prm_string

parameter_explanations(tablefmt='presto')[source]#

Returns a string providing short explanations on the defined parameters.

Parameters

tablefmt (str) – An argument for the tabulate function defining the style of the generated table. Check out tabulate’s documentation for more info.

Returns

This string describes a nice table with short explanations on the parameters of the problem.

Return type

prm_string

property prior_prms: List[str]#

Access the names of all ‘prior’-parameters as an attribute.

property prms: List[str]#

Access the names of all parameters as an attribute.

property value_dict: dict#

Returns a dict with the parameter names as keys and their numeric values as values. A parameter will only have a value if it is a constant. For latent parameters the dictionary-value will be None

class ScalarInterval(lower_bound, upper_bound, lower_bound_included, upper_bound_included)[source]#

Bases: object

Describes a one-dimensional interval. Used for the domain-definition of parameters.

Parameters
  • lower_bound (float) – The lower bound of the interval (if the interval is [a, b], this here is a).

  • upper_bound (float) – The upper bound of the interval (if the interval is [a, b], this here is b).

  • lower_bound_included (bool) – Defines if the lower bound is included in the interval.

  • upper_bound_included (bool) – Defines if the upper bound is included in the interval.

check_bounds_inc_inc(value)[source]#

Checks if a given value is within the specified bounds (where both bounds are included).

Parameters

value (Union[int, float]) – The given scalar value.

Return type

True, if the value is within its bounds, otherwise False is returned.

check_bounds_inc_ninc(value)[source]#

Checks if a given value is within the specified bounds (where only the lower bound is included).

Parameters

value (Union[int, float]) – The given scalar value.

Return type

True, if the value is within its bounds, otherwise False is returned.

check_bounds_ninc_inc(value)[source]#

Checks if a given value is within the specified bounds (where only the upper bound is included).

Parameters

value (Union[int, float]) – The given scalar value.

Return type

True, if the value is within its bounds, otherwise False is returned.

check_bounds_ninc_ninc(value)[source]#

Checks if a given value is within the specified bounds (where only the upper bound is included).

Parameters

value (Union[int, float]) – The given scalar value.

Return type

True, if the value is within its bounds, otherwise False is returned.

prior#

class PriorBase(ref_prm, prms_def, name, dist)[source]#

Bases: object

Template class for prior definitions. Note that the main motivation of how this class is implemented was to avoid storing any numeric values for any of the priors parameters within the prior object.

Parameters
  • ref_prm (str) – The name of the latent parameter the prior refers to.

  • prms_def (Union[str, dict, List[Union[str, dict]]]) – A list of strings, or list of one-element-dicts defining the prior’s parameter names. For example [‘mean_a’, ‘std_a’] or {‘mean_a’: ‘std_a’, ‘std_a’: ‘std_a’}. The latter example is the notation for the use of global and local names, which should not be necessary for the definition of prior-parameters. A special case is the uninformative prior (see below) which hasn’t got an parameters. So, in this case prms_def might also be None.

  • name (str) – Defining the priors name.

  • dist (probeye.definition.distribution.ProbabilityDistribution) – The probability distribution that describes the prior.

property prior_type: str#

Dynamically accesses the prior’s distribution type from its dist-object.

distribution#

class LogNormal(mean, std)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Log-normal probability distribution (univariate). For more information check out https://en.wikipedia.org/wiki/Log-normal_distribution.

Parameters
  • mean (Union[int, float, str]) – The mean value of the distribution on the log-scale. Either a number, or a string that describes the name of the parameter that defines the value.

  • std (Union[int, float, str]) – The standard deviation of the distribution on the log-scale. Either a number, or a string that describes the name of the parameter that defines the value.

class MultivariateNormal(mean, cov)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Normal or Gaussian probability distribution (multivariate). For more information check out https://en.wikipedia.org/wiki/Multivariate_normal_distribution.

Parameters
  • mean (Union[numpy.ndarray, str]) – The mean value of the distribution. Either a vector, or a string that describes the name of the parameter that defines the value.

  • cov (Union[numpy.ndarray, str]) – The covariance matrix of the distribution. Either an array, or a string that describes the name of the parameter that defines the value.

class Normal(mean, std)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Normal or Gaussian probability distribution (univariate). For more information check out https://en.wikipedia.org/wiki/Normal_distribution.

Parameters
  • mean (Union[int, float, str]) – The mean value of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • std (Union[int, float, str]) – The standard deviation of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

class ProbabilityDistribution(dist_type)[source]#

Bases: object

Base class for the different (specific) probability distributions defined below. All of these classes have in common that they merely describe the respective distribution without providing any computing routines. The latter are overloaded when the problem is handed over to a solver.

Parameters

dist_type (str) – The type of the distribution. For example ‘normal’ or ‘uniform’.

static _plot(x, y, ax, color, rotate, adjusted_left, adjusted_right, label)[source]#

Basic plotting function for plotting the distributions probability density function (pdf).

Parameters
  • x (Union[numpy.ndarray, list, tuple, float, int]) – The values on the (un-rotated) x-axis of the pdf-plot.

  • y (Union[numpy.ndarray, list, tuple, float, int]) – The values on the (un-rotated) y-axis of the pdf-plot.

  • ax (plt.Axes) – The axis object to plot the prior-pdf on.

  • color (str) – The line-color of the prior-pdf’s graph.

  • rotate (bool) – If True, the x- and y-axis are switched. This is required, for example, in a pair-plot with two parameters. Here, the histogram to the right is rotated by 90 degrees.

  • adjusted_left (Union[int, float]) – Left limit of (un-rotated) x-axis. Typically adjusted with a margin.

  • adjusted_right (Union[int, float]) – Right limit of (un-rotated) x-axis. Typically adjusted with a margin.

  • label (str) – The label used in the legend of the plot for the plotted pdf.

plot(primary_var, ax, prms, x=None, n_points=200, color='darkorange', rotate=False, label='pdf')[source]#

Template for plotting method which plots the prior-pdf to a given axis object.

Parameters
  • primary_var (str) – The reference parameter of the distribution. For example, if one considers a normal distribution with a density called f, which one would evaluate via f(x, mean=0, std=1), then x would be the reference parameter.

  • ax (plt.Axes) – The axis object to plot the prior-pdf on.

  • prms (Parameters) – The parameters of the problem at hand. Essentially a dictionary. But the values are ParameterProperties-objects.

  • x (Optional[numpy.ndarray]) – The points where the prior-pdf should be evaluated at. If None is given, x will be derived from the x-limits of the given ax-object.

  • n_points (int) – The number of points of the prior-pdf graph. Only effective when x is None.

  • color (str) – The line-color of the prior-pdf’s graph.

  • rotate (bool) – If True, the x- and y-axis are switched. This is required, for example, in a pair-plot with two parameters. Here, the histogram to the right is rotated by 90 degrees.

  • label – The label used in the legend of the plot for the plotted pdf.

class SampleBased(samples)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Probability distribution defined via a number of samples (univariate). For more information check out https://en.wikipedia.org/wiki/Sampling_distribution.

Parameters

samples (Union[numpy.ndarray, str]) – The samples, the distribution is based on. Either a vector, or a string that describes the name of the parameter that defines the value.

class TruncNormal(mean, std, low, high)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Truncated normal or Gaussian probability distribution (univariate). For more information check out https://en.wikipedia.org/wiki/Truncated_normal_distribution.

Parameters
  • mean (Union[int, float, str]) – The mean value of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • std (Union[int, float, str]) – The standard deviation of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • low (Union[int, float, str]) – The lower bound of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • high (Union[int, float, str]) – The upper bound of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

class Uniform(low, high)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Uniform probability distribution (univariate) with bounds included. For more information check out https://en.wikipedia.org/wiki/Continuous_uniform_distribution.

Parameters
  • low (Union[int, float, str]) – The lower bound of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • high (Union[int, float, str]) – The upper bound of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

class Uninformative[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Represents a univariate uniform distribution with bounds “at” +/- infinity. This distribution (whose internal purpose is that of a tag) is automatically assigned to a parameter that is added to an inverse problem that is neither assigned a prior nor a value. For example, problem.add_parameter(“a”).

class Weibull(scale, shape)[source]#

Bases: probeye.definition.distribution.ProbabilityDistribution

Two-parameter Weibull distribution (univariate). For more information check out https://en.wikipedia.org/wiki/Weibull_distribution.

Parameters
  • scale (Union[int, float, str]) – The scale-parameter of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

  • shape (Union[int, float, str]) – The shape-parameter of the distribution. Either a number, or a string that describes the name of the parameter that defines the value.

sensor#

class Sensor(name, measurand='not defined', unit='not defined', x=None, y=None, z=None, coords=None, order=('x', 'y', 'z'), std_model='not defined')[source]#

Bases: dict

Base class for an input or output sensor of the forward model. In its simplest form an instance of this class is just a dictionary with a ‘name’ attribute. Additional attributes for the measured quality (measurand) and the corresponding unit can be defined as well. If the sensors position(s) are important, they can be defined as attributes. Further attributes can be defined by the user by creating new classes derived from this one. If the sensor is used as an output sensor, the parameters that describe the statistics of the error in this sensor must be given. Moreover, a sensor objects points to the experimental data it refers to. For that purpose, the sensor class is derived from the dictionary class (so, essentially, a sensor is a dictionary with additional attributes). The keys of an output sensor are the experiment’s names in which some data for this sensor was collected. Consequently, the values are the measured values of the sensor in the respective experiment.

Parameters
  • name (str) – The name of the sensor, for example ‘T_in’, ‘v_x’ or just ‘y’. Note that the sensor’s name must be unique among all the sensors of the forward model the sensor was defined on. The name of the sensor does not have to be unique across multiple forward models though. So, for example, if there are two forward models defined in an inverse problem, they can both have a sensor named ‘y’.

  • measurand (str) – Defines what the sensor measures, for example ‘temperature’ or ‘deflection’. Note that this is optional information, which is currently not used elsewhere in the code.

  • unit (str) – Defines what unit is associated with the sensor’s measurements, for example ‘mm’ for a deflection or ‘K’ for a temperature.

  • std_model (str) – The name of the globally defined parameter that describes the standard deviation of the model prediction error in this sensor. If multiple output sensors are defined on a forward model, these sensors can have different parameters that describe their model prediction error..

  • x (Optional[Union[float, int, numpy.ndarray]]) – x-coordinate(s) of the sensor. When given, the coords- argument must be None. Usually, this value will be a scalar (for example if the sensor represents a point-like sensor like a strain gauge), but the value can also be a vector. This can make sense, for example, for an optical measurement system, which tracks the deflections of multiple points on a loaded structure. If next to ‘x’ also ‘y’ and/or ‘z’ are given, they must all have the same length.

  • y (Optional[Union[float, int, numpy.ndarray]]) – y-coordinate(s) of the sensor. When given, the coords- argument must be None. Check out the explanations of ‘x’ for more information.

  • z (Optional[Union[float, int, numpy.ndarray]]) – z-coordinate(s) of the sensor. When given, the coords-argument must be None. Check out the explanations of ‘x’ for more information.

  • coords (Optional[numpy.ndarray]) – Some or all of the coordinates x, y, z concatenated as an array. Each row corresponds to a constant coordinate, for example the first row might contain all values for the x-coordinate of all points. Which row corresponds to which coordinate is defined via the order-argument. When ‘coords’ given, the arguments ‘x’, ‘y’ and ‘z’ must be None.

  • order (Tuple[str, ...]) – Only relevant when ‘coords’ is given. Defines which row in ‘coords’ corresponds to which coordinate. For example, order=(‘x’, ‘y’, ‘z’) means that the 1st row of ‘coords’ contains x-coordinates while the 2nd row contains y-coords and the 3rd row contains the z-coordinates.

property order: List[str]#

Provides read-access to privat attribute self._order.

property x: Optional[numpy.ndarray]#

Provides x-coords as attribute without copying them from coords.

property y: Optional[numpy.ndarray]#

Provides y-coords as attribute without copying them from coords.

property z: Optional[numpy.ndarray]#

Provides z-coords as attribute without copying them from coords.

probeye.inference#

solver#

class Solver(problem, seed=None, show_progress=True)[source]#

Bases: object

Base class for the different solvers (inference engines).

Parameters
  • problem (InverseProblem) – Describes the inverse problem including e.g. parameters and data.

  • seed (Optional[int]) – Random state used for random number generation.

  • show_progress (bool) – When True, the progress of a solver routine will be shown (for example as a progress-bar) if such a feature is available. Otherwise, the progress will not shown.

_translate_experiments()[source]#

Translate the inverse problem’s experiments as needed for this solver.

_translate_forward_models()[source]#

Translate the inverse problem’s forward models as needed for this solver.

_translate_likelihood_models()[source]#

Translate the inverse problem’s likelihood models as needed for this solver.

_translate_parameters()[source]#

Translate the inverse problem’s parameters as needed for this solver.

scipy-solver#

class MaxLikelihoodSolver(problem, seed=None, show_progress=True)[source]#

Bases: probeye.inference.scipy.solver.ScipySolver

Solver for a maximum likelihood estimation. This class is separate from ScipySolver so that its main function can be triggered by a ‘run’-method. For information on the arguments see Solver.

Parameters
  • problem (InverseProblem) –

  • seed (Optional[int]) –

  • show_progress (bool) –

run(x0_dict=None, x0_prior='mean', x0_default=1.0, true_values=None, method='Nelder-Mead', solver_options=None)[source]#

Triggers a maximum likelihood estimation. For more information on the arguments check out probeye.inference.scipy.solver._run_ml_or_map().

Parameters
  • x0_dict (Optional[dict]) –

  • x0_prior (str) –

  • x0_default (float) –

  • true_values (Optional[dict]) –

  • method (str) –

  • solver_options (Optional[dict]) –

Return type

scipy.optimize._optimize.OptimizeResult

class MaxPosteriorSolver(problem, seed=None, show_progress=True)[source]#

Bases: probeye.inference.scipy.solver.ScipySolver

Solver for maximum a-posteriori estimation. This class is separate from ScipySolver so that its main function can be triggered by a ‘run’-method. For information on the arguments see Solver.

Parameters
  • problem (InverseProblem) –

  • seed (Optional[int]) –

  • show_progress (bool) –

run(x0_dict=None, x0_prior='mean', x0_default=1.0, true_values=None, method='Nelder-Mead', solver_options=None)[source]#

Triggers a maximum a-posteriori estimation. For more information on the args check out probeye.inference.scipy.solver._run_ml_or_map().

Parameters
  • x0_dict (Optional[dict]) –

  • x0_prior (str) –

  • x0_default (float) –

  • true_values (Optional[dict]) –

  • method (str) –

  • solver_options (Optional[dict]) –

Return type

scipy.optimize._optimize.OptimizeResult

class ScipySolver(problem, seed=None, show_progress=True)[source]#

Bases: probeye.inference.solver.Solver

Solver based on scipy and numpy for an InverseProblem. The ScipySolver contains the methods for log-prior and log-likelihood evaluation. For information on the arguments see Solver.

Parameters
  • problem (InverseProblem) –

  • seed (Optional[int]) –

  • show_progress (bool) –

_run_ml_or_map(x0_dict=None, x0_prior='mean', x0_default=1.0, true_values=None, method='Nelder-Mead', solver_options=None, use_priors=True)[source]#

Finds values for an InverseProblem’s latent parameters that maximize the problem’s likelihood or likelihood * prior function. The used method is scipy’s minimize function from the optimize submodule.

Parameters
  • x0_dict (Optional[dict]) – Contains the start values for each latent variable. Via this arg the user can explicitly specify a start value for the optimization.

  • x0_prior (str) – If x0_dict is not given, the start values will be derived from the priors, either using the ‘mean’ or ‘median’ value. If x0_dict is given, this argument has no effect. Valid values are ‘mean’ and ‘median’.

  • x0_default (float) – For uninformative priors, no mean or median value is defined. In those cases, the default_x0 value will be used as start value. If x0_dict is given, this argument has no effect.

  • true_values (Optional[dict]) – Defines ‘true’ parameter values. Keys are the parameter names and values are the ‘true’ values. They are only used to print them next to the inferred parameter values from the optimization run.

  • method (str) – Defines the algorithm used by scipy.optimize.minimize. See the documentation of this scipy method to see all the options.

  • solver_options (Optional[dict]) – Options passed to scipy.optimize.minimize under the ‘options’ keyword arg. See the documentation of this scipy method to see available options.

  • use_priors (bool) – When True, the priors are included in the objective function (MAP). Otherwise, the priors are not included (ML).

Returns

An object returns by scipy’s minimize function containing the optimization results. The parameter vector that optimizes the likelihood function can be requested via ‘minimize_results.x’.

Return type

minimize_results

_translate_experiments()[source]#

Translate the inverse problem’s experiments as needed for this solver.

_translate_forward_models()[source]#

Translate the inverse problem’s forward models as needed for this solver.

_translate_likelihood_models()[source]#

Translate the inverse problem’s likelihood models as needed for this solver.

_translate_parameters()[source]#

Translate the inverse problem’s parameters as needed for this solver.

evaluate_model_response(theta, forward_model, experiment_name)[source]#

Evaluates the model response for each forward model for the given parameter vector theta and the given experiments.

Parameters
  • theta (numpy.ndarray) – A numeric vector for which the model responses should be evaluated. Which parameters these numbers refer to can be checked by calling self.theta_explanation() once the problem is set up.

  • forward_model (ForwardModelBase) – The forward model that should be evaluated.

  • experiment_name (str) – The experiment, the forward model should be evaluated for.

Returns

  • model_response_vector – Vector of the model responses (concatenated over output sensors).

  • residuals_vector – Vector of the model residuals (concatenated over output sensors).

Return type

Tuple[numpy.ndarray, numpy.ndarray]

get_start_values(x0_dict=None, x0_prior='mean', x0_default=1.0)[source]#

Derives the start values for the maximum likelihood optimization run. For an explanation of the arguments, see self.run_max_likelihood.

Returns

  • x0 – A numeric vector with the derived start values in the order of InverseProblem.get_theta_names().

  • x0_dict – Keys are the latent parameters, while the keys are their start values.

Parameters
  • x0_dict (Optional[dict]) –

  • x0_prior (str) –

  • x0_default (float) –

Return type

Tuple[numpy.ndarray, dict]

loglike(theta)[source]#

Evaluates the log-likelihood function of the problem at theta.

Parameters

theta (numpy.ndarray) – A numeric vector for which the log-likelihood function should be evaluated. Which parameters these numbers refer to can be checked by calling self. theta_explanation() once the problem is set up.

Returns

The evaluated log-likelihood function for the given theta-vector.

Return type

ll

logprior(theta)[source]#

Evaluates the log-prior function of the problem at theta.

Parameters

theta (numpy.ndarray) – A numeric vector for which the log-likelihood function should be evaluated. Which parameters these numbers refer to can be checked by calling self. theta_explanation() once the problem is set up.

Returns

The evaluated log-prior function for the given theta-vector.

Return type

lp

sample_from_prior(prm_name, size)[source]#

Generates random samples from a parameter’s prior distribution and returns the generated samples.

Parameters
  • prm_name (str) – The name of the parameter the prior is associated with.

  • size (int) – The number of random samples to be drawn.

Return type

The generated samples.

summarize_point_estimate_results(minimize_results, true_values, x0_dict, estimate_type='maximum likelihood estimation')[source]#

Prints a summary of the results of the maximum likelihood estimation. For an explanation of the arguments, check out the docstring of the self.run_max_likelihood-method.

Parameters
  • minimize_results (scipy.optimize._optimize.OptimizeResult) –

  • true_values (Optional[dict]) –

  • x0_dict (dict) –

  • estimate_type (str) –

emcee-solver#

class EmceeSolver(problem, seed=None, show_progress=True)[source]#

Bases: probeye.inference.scipy.solver.ScipySolver

Provides emcee-sampler which is a pure-Python implementation of Goodman & Weare’s Affine Invariant Markov chain Monte Carlo (MCMC) Ensemble sampler. For more information, check out https://emcee.readthedocs.io/en/stable/.

Parameters
  • problem (InverseProblem) – Describes the inverse problem including e.g. parameters and data.

  • seed (Optional[int]) – Random state used for random number generation.

  • show_progress (bool) – When True, the progress of a solver routine will be shown (for example as a progress-bar) if such a feature is available. Otherwise, the progress will not shown.

emcee_summary(posterior_samples, true_values=None)[source]#

Computes and prints a summary of the posterior samples containing mean, median, standard deviation, 5th percentile and 95th percentile. Note, that this method was based on code from the taralli package: https://gitlab.com/tno-bim/taralli.

Parameters
  • posterior_samples (numpy.ndarray) – The generated samples in an array with as many columns as there are latent parameters, and n rows, where n = n_chains * n_steps.

  • true_values (Optional[dict]) – True parameter values, if known.

Returns

  • Keys are the different statistics ‘mean’, ‘median’, ‘sd’ (standard

  • deviation), ‘q05’ and ‘q95’ (0.05- and 0.95-quantile). The values are

  • dictionaries with the parameter names as keys and the respective statistics

  • as values.

Return type

dict

run(n_walkers=20, n_steps=1000, n_initial_steps=100, true_values=None, **kwargs)[source]#

Runs the emcee-sampler for the InverseProblem the EmceeSolver was initialized with and returns the results as an arviz InferenceData obj.

Parameters
  • n_walkers (int) – Number of walkers used by the estimator.

  • n_steps (int) – Number of steps to run.

  • n_initial_steps (int) – Number of steps for initial (burn-in) sampling.

  • true_values (Optional[dict]) – True parameter values, if known.

  • kwargs – Additional key-word arguments channeled to emcee.EnsembleSampler.

Returns

Contains the results of the sampling procedure.

Return type

inference_data

dynesty-solver#

class DynestySolver(problem, seed=None, show_progress=True)[source]#

Bases: probeye.inference.scipy.solver.ScipySolver

A static and dynamic nested parameter estimator. It facilitates the use of the python package dynesty. The default is set to a static parameter estimator.

_Note:_ For full details on the dynesty library see:

https://dynesty.readthedocs.io/en/latest/index.html.

Parameters
  • problem (InverseProblem) – Describes the inverse problem including e.g. parameters and data.

  • seed (Optional[int]) – Random state used for random number generation.

  • show_progress (bool) – When True, the progress of a solver routine will be shown (for example as a progress-bar) if such a feature is available. Otherwise, the progress will not shown.

get_summary(posterior_samples, true_values=None)[source]#

Computes and prints a summary of the posterior samples containing mean, median, standard deviation, 5th percentile and 95th percentile. Note, that this method was based on code from the taralli package: https://gitlab.com/tno-bim/taralli.

Parameters
  • posterior_samples (numpy.ndarray) – The generated samples in an array with as many columns as there are latent parameters, and n rows, where n = n_chains * n_steps.

  • true_values (Optional[dict]) – True parameter values, if known.

Returns

  • Keys are the different statistics ‘mean’, ‘median’, ‘sd’ (standard

  • deviation), ‘q05’ and ‘q95’ (0.05- and 0.95-quantile). The values are

  • dictionaries with the parameter names as keys and the respective statistics

  • as values.

Return type

dict

prior_transform(theta)[source]#

Evaluates the ppf of the prior distributions at theta.

Parameters

theta (numpy.ndarray) – A numeric vector for which the ppf should be evaluated. Which parameters these numbers refer to can be checked by calling self. theta_explanation() once the problem is set up.

Returns

The vector of quantiles for each prior distribution at theta.

Return type

qs

run(estimation_method='dynamic', nlive=250, true_values=None, **kwargs)[source]#

Runs the dynesty-sampler for the InverseProblem the DynestySolver was initialized with and returns the results as an arviz InferenceData obj.

Parameters
  • estimation_method (str) – “dynamic” or “static”

  • nlive (int) – number of live points

  • true_values (Optional[dict]) – True parameter values, if known.

  • kwargs – Additional key-word arguments channeled to emcee.EnsembleSampler.

Returns

Contains the results of the sampling procedure.

Return type

inference_data or dynesty sampler

probeye.postprocessing#

sampling_plots#

create_pair_plot(inference_data, problem, plot_with='arviz', plot_priors=True, focus_on_posterior=True, kind='kde', figsize=None, inches_per_row=2.0, inches_per_col=2.0, textsize=10, title_size=14, title=None, true_values=None, show_legends=True, show=True, **kwargs)[source]#

Creates a pair-plot for the given inference data.

Parameters
  • inference_data (arviz.data.inference_data.InferenceData) – Contains the results of the sampling procedure.

  • problem (InverseProblem) – The inverse problem the inference data refers to.

  • plot_with (str) – Defines the python package the plot will be generated with. Options are: {‘arviz’, ‘seaborn’, ‘matplotlib’}.

  • plot_priors (bool) – If True, the prior-distributions are included in the marginal subplots. Otherwise the priors are not shown.

  • focus_on_posterior (bool) – If True, the marginal plots will focus on the posteriors, i.e., the range of the horizontal axis will adapt to the posterior. This might result in just seeing a fraction of the prior distribution (if they are included). If False, the marginal plots will focus on the priors, which will have a broader x-range. If plot_priors=False, this argument has no effect on the generated plot.

  • kind (str) – Type of plot to display (‘scatter’, ‘kde’ and/or ‘hexbin’).

  • figsize (Optional[tuple]) – Defines the size of the generated plot in inches. If None is chosen, the figsize will be derived automatically by using inches_per_row and inches_per_col.

  • inches_per_row (Union[int, float]) – If figsize is None, this will specify the inches per row in the subplot-grid. This argument has no effect if figsize is specified.

  • inches_per_col (Union[int, float]) – If figsize is None, this will specify the inches per column in the subplot-grid. This argument has no effect if figsize is specified.

  • textsize (Union[int, float]) – Defines the font size in the default unit.

  • title_size (Union[int, float]) – Defines the font size of the figures title if ‘title’ is given.

  • title (Optional[str]) – The title of the figure.

  • true_values (Optional[dict]) – Used for plotting ‘true’ parameter values. Keys are the parameter names and values are the values that are supposed to be shown in the marginal plots.

  • show_legends (bool) – If True, legends are shown in the marginal plots. Otherwise no legends are included in the plot.

  • show (bool) – When True, the show-method is called after creating the plot. Otherwise, the show-method is not called. The latter is useful, when the plot should be further processed.

  • kwargs – Additional keyword arguments passed to arviz’ pairplot function.

Returns

The array of subplots of the created plot.

Return type

axs

create_posterior_plot(inference_data, problem, plot_with='arviz', kind='hist', figsize=None, inches_per_row=3.0, inches_per_col=2.5, textsize=10, title_size=14, title=None, hdi_prob=0.95, true_values=None, show=True, **kwargs)[source]#

Creates a posterior-plot for the given inference data.

Parameters
  • inference_data (arviz.data.inference_data.InferenceData) – Contains the results of the sampling procedure.

  • problem (InverseProblem) – The inverse problem the inference data refers to.

  • plot_with (str) – Defines the python package the plot will be generated with. Options are: {‘arviz’, ‘seaborn’, ‘matplotlib’}.

  • kind (str) – Type of plot to display (‘kde’ or ‘hist’).

  • figsize (Optional[tuple]) – Defines the size of the generated plot in inches. If None is chosen, the figsize will be derived automatically by using inches_per_row and inches_per_col.

  • inches_per_row (Union[int, float]) – If figsize is None, this will specify the inches per row in the subplot-grid. This argument has no effect if figsize is specified.

  • inches_per_col (Union[int, float]) – If figsize is None, this will specify the inches per column in the subplot-grid. This argument has no effect if figsize is specified.

  • textsize (Union[int, float]) – Defines the font size in the default unit.

  • title_size (Union[int, float]) – Defines the font size of the figures title if ‘title’ is given.

  • title (Optional[str]) – The title of the figure.

  • hdi_prob (float) – Defines the highest density interval. Must be a number between 0 and 1.

  • true_values (Optional[dict]) – Used for plotting ‘true’ parameter values. Keys are the parameter names and values are the values that are supposed to be shown in the marginal plots.

  • show (bool) – When True, the show-method is called after creating the plot. Otherwise, the show-method is not called. The latter is useful, when the plot should be further processed.

  • kwargs – Additional keyword arguments passed to arviz’ plot_posterior function.

Returns

The array of subplots of the created plot.

Return type

axs

create_trace_plot(inference_data, problem, plot_with='arviz', kind='trace', figsize=None, inches_per_row=2.0, inches_per_col=3.0, textsize=10, title_size=14, title=None, show=True, **kwargs)[source]#

Creates a trace-plot for the given inference data.

Parameters
  • inference_data (arviz.data.inference_data.InferenceData) – Contains the results of the sampling procedure.

  • problem (InverseProblem) – The inverse problem the inference data refers to.

  • plot_with (str) – Defines the python package the plot will be generated with. Options are: {‘arviz’, ‘seaborn’, ‘matplotlib’}.

  • kind (str) – Allows to choose between plotting sampled values per iteration (“trace”) and rank plots (“rank_bar”, “rank_vlines”).

  • figsize (Optional[tuple]) – Defines the size of the generated plot in inches. If None is chosen, the figsize will be derived automatically by using inches_per_row and inches_per_col.

  • inches_per_row (Union[int, float]) – If figsize is None, this will specify the inches per row in the subplot-grid. This argument has no effect if figsize is specified.

  • inches_per_col (Union[int, float]) – If figsize is None, this will specify the inches per column in the subplot-grid. This argument has no effect if figsize is specified.

  • textsize (Union[int, float]) – Defines the font size in the default unit.

  • title_size (Union[int, float]) – Defines the font size of the figures title if ‘title’ is given.

  • title (Optional[str]) – The title of the figure.

  • show (bool) – When True, the show-method is called after creating the plot. Otherwise, the show-method is not called. The latter is useful, when the plot should be further processed.

  • kwargs – Additional keyword arguments passed to arviz’ plot_trace function.

Returns

The array of subplots of the created plot.

Return type

axs