interface#

import tensorwaves.interface

Defines top-level interface of tensorwaves.

class InputType#

The argument type of a Function.__call__().

alias of TypeVar(‘InputType’)

class OutputType#

The return type of a Function.__call__().

alias of TypeVar(‘OutputType’)

class Function[source]#

Bases: ABC, Generic[InputType, OutputType]

Generic representation of a mathematical function.

Representation of a mathematical function that computes OutputType values (co-domain) for a given set of InputType values (domain). Examples of Function are ParametrizedFunction, Estimator and DataTransformer.

abstract __call__(data: InputType) OutputType[source]#

Call self as a function.

DataSample#

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

alias of Dict[str, ndarray]

ParameterValue#

Allowed types for parameter values.

alias of Union[complex, float]

class ParametrizedFunction[source]#

Bases: Function[InputType, OutputType]

Interface of a callable function.

A ParametrizedFunction identifies certain variables in a mathematical expression as parameters. Remaining variables are considered domain variables. Domain variables are the argument of the evaluation (see __call__()), while the parameters are controlled via parameters (getter) and update_parameters() (setter). This mechanism is especially important for an Estimator.

abstract __call__(data: InputType) OutputType[source]#

Call self as a function.

abstract property parameters: dict[str, ParameterValue][source]#

Get dict of parameters.

abstract update_parameters(new_parameters: Mapping[str, ParameterValue]) None[source]#

Update the collection of parameters.

class DataTransformer[source]#

Bases: Function[Dict[str, ndarray], Dict[str, ndarray]]

Transform one DataSample into another DataSample.

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

class Estimator[source]#

Bases: Function[Mapping[str, Union[complex, float]], float]

Estimator for discrepancy model and data.

See the estimator module for different implementations of this interface.

abstract __call__(parameters: Mapping[str, ParameterValue]) float[source]#

Compute estimator value for this combination of parameter values.

abstract gradient(parameters: Mapping[str, ParameterValue]) dict[str, ParameterValue][source]#

Calculate gradient for given parameter mapping.

class FitResult(minimum_valid: bool, execution_time: float, function_calls: int, estimator_value: float, parameter_values: dict[str, ParameterValue] | None = None, parameter_errors: dict[str, ParameterValue] | None = None, iterations: int | None = None, specifics: Any | None = None)[source]#

Bases: object

minimum_valid: bool[source]#
execution_time: float[source]#
function_calls: int[source]#
estimator_value: float[source]#
parameter_values: dict[str, ParameterValue][source]#
parameter_errors: dict[str, ParameterValue] | None[source]#
iterations: int | None[source]#
specifics: Any | None[source]#

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.

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

Compute the number of free parameters in a FitResult.

Parameters:

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

class Optimizer[source]#

Bases: ABC

Optimize a fit model to a data set.

See the optimizer module for different implementations of this interface.

abstract optimize(estimator: Estimator, initial_parameters: Mapping[str, ParameterValue]) FitResult[source]#

Execute optimization.

class RealNumberGenerator[source]#

Bases: ABC

Abstract class for generating real numbers within a certain range.

Implementations can be found in the tensorwaves.data module.

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

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

abstract property seed: float | None[source]#

Get random seed.

None if you want indeterministic behavior.

class DataGenerator[source]#

Bases: ABC

Abstract class for generating a DataSample.

abstract generate(size: int, rng: RealNumberGenerator) DataSample[source]#

Generate a DataSample with size events.

Returns:

A tuple of a DataSample with an array of weights.