interface

import tensorwaves.interface

Defines top-level interface of tensorwaves.

DataSample

Mapping of variable names to a sequence of data points, used by Function.

alias of Mapping[Union[int, str], numpy.ndarray]

class DataTransformer[source]

Bases: abc.ABC

Interface of a data converter.

abstract transform(dataset: Mapping[Union[int, str], ndarray]) Mapping[Union[int, str], ndarray][source]

Transform a dataset into another dataset.

This changes the keys and values of the input DataSample to a specific output DataSample structure.

class Estimator[source]

Bases: abc.ABC

Estimator for discrepancy model and data.

abstract __call__(parameters: Mapping[str, Union[complex, float]]) float[source]

Evaluate discrepancy.

abstract gradient(parameters: Mapping[str, Union[complex, float]]) Dict[str, Union[complex, float]][source]

Calculate gradient for given parameter mapping.

class FitResult(minimum_valid: bool, execution_time: float, function_calls: int, estimator_value: float, parameter_values: Optional[Dict[str, Union[complex, float]]] = None, parameter_errors: Optional[Dict[str, Union[complex, float]]] = None, iterations: Optional[int] = None, specifics: Optional[Any] = None)[source]

Bases: object

__eq__(other)

Method generated by attrs for class FitResult.

count_number_of_parameters(complex_twice: bool = False) int[source]

Compute the number of free parameters in a FitResult.

Parameters
  • fit_result (FitResult) – Fit result from which to count it’s parameter_values.

  • complex_twice (bool) – Count complex-valued parameters twice.

estimator_value: float
execution_time: float
function_calls: int
iterations: Optional[int]
minimum_valid: bool
parameter_errors: Optional[Dict[str, Union[complex, float]]]
parameter_values: Dict[str, Union[complex, float]]
specifics: Optional[Any]

Any additional info provided by the specific optimizer.

An instance returned by one of the implemented optimizers under the optimizer module. Currently one of:

This way, you can for instance get the covariance matrix. See also Covariance matrix.

class Function[source]

Bases: abc.ABC

Interface of a callable function.

The parameters of the model are separated from the domain variables. This follows the mathematical definition, in which a function defines its domain and parameters. However specific points in the domain are not relevant. Hence while the domain variables are the argument of the evaluation (see __call__()), the parameters are controlled via a getter and setter (see parameters()). The reason for this separation is to facilitate the events when parameters have changed.

abstract __call__(dataset: Mapping[Union[int, str], ndarray]) ndarray[source]

Evaluate the function.

Parameters

dataset – a dict with domain variable names as keys.

Returns

ReactionInfo of the function evaluation. Type depends on the input type.

abstract property parameters: Dict[str, Union[complex, float]]

Get dict of parameters.

abstract update_parameters(new_parameters: Mapping[str, Union[complex, float]]) None[source]

Update the collection of parameters.

class Model[source]

Bases: abc.ABC

Interface of a model which can be lambdified into a callable.

property argument_order: Tuple[str, ...]

Order of arguments of lambdified function signature.

abstract lambdify(backend: Union[str, tuple, dict]) Callable[source]

Lambdify the model into a Callable.

Parameters

backend – Choice of backend for fast evaluations.

The arguments of the Callable are union of the variables and parameters. The return value of the Callable is Any. In theory the return type should be a value type depending on the model. Currently, there no typing support is implemented for this.

abstract property parameters: Dict[str, Union[complex, float]]

Get mapping of parameters to suggested initial values.

abstract performance_optimize(fix_inputs: Mapping[Union[int, str], ndarray]) Model[source]

Create a performance optimized model, based on fixed inputs.

abstract property variables: FrozenSet[str]

Expected input variable names.

class Optimizer[source]

Bases: abc.ABC

Optimize a fit model to a data set.

abstract optimize(estimator: Estimator, initial_parameters: Mapping[str, Union[complex, float]]) FitResult[source]

Execute optimization.

ParameterValue

Allowed types for parameter values.

alias of Union[complex, float]

class PhaseSpaceGenerator[source]

Bases: abc.ABC

Abstract class for generating phase space samples.

abstract generate(size: int, rng: UniformRealNumberGenerator) Tuple[Mapping[Union[int, str], ndarray], ndarray][source]

Generate phase space sample.

Returns

A tuple of a DataSample (four-momenta) with an event-wise sequence of weights. The four-momenta are arrays of shape \(n \times 4\).

abstract setup(initial_state_mass: float, final_state_masses: Mapping[int, float]) None[source]

Hook for initialization of the PhaseSpaceGenerator.

Called before any generate() calls.

Parameters
  • initial_state_mass – Mass of the decaying state.

  • final_state_masses – A mapping of final state IDs to the corresponding masses.

class UniformRealNumberGenerator[source]

Bases: abc.ABC

Abstract class for generating uniform real numbers.

abstract __call__(size: int, min_value: float = 0.0, max_value: float = 1.0) ndarray[source]

Generate random floats in the range from [min_value,max_value).

abstract property seed: Optional[float]

Get random seed. None if you want indeterministic behavior.