saftig.evaluation.metrics¶
Methods of evaluation noise cancellation performance.
Attributes¶
Classes¶
Parent class for evaluation metrics |
|
Parent class for evaluation metrics that yield a scalar value |
|
Parent class for evaluation metrics that provide a plotting feature |
|
The RMS of the residual signal |
|
The MSE of the residual signal |
|
The signal power on a given frequency range |
|
Plots the PSD of the given signal |
Functions¶
|
Apply scipy.signal.welch to a sequence of arrays |
Module Contents¶
- saftig.evaluation.metrics.Self¶
- saftig.evaluation.metrics.welch_multiple_sequences(arrays, nperseg, *args, **kwargs)¶
Apply scipy.signal.welch to a sequence of arrays
Additional arguments are passed to the scipy Welch implementation. Spectra are combined with an average weighted by the array lengths. If sequences
- Parameters:
arrays (collections.abc.Sequence[numpy.typing.NDArray]) – Sequence of arrays
nperseg – Length of FFT segments
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray]
- class saftig.evaluation.metrics.EvaluationMetric(**kwargs)¶
Bases:
abc.ABCParent class for evaluation metrics
- applied = False¶
- prediction: collections.abc.Sequence[numpy.typing.NDArray]¶
- residual: collections.abc.Sequence[numpy.typing.NDArray]¶
- parameters: dict¶
- name: str¶
- method_hash_value: bytes¶
- static init_wrapper(func)¶
A decorator for the __init__function
Saves a hash value for the configuration
- apply(prediction, dataset)¶
Apply this filter
- Parameters:
prediction (collections.abc.Sequence[numpy.typing.NDArray]) –
dataset (saftig.evaluation.dataset.EvaluationDataset) –
- Return type:
Self
- property result_full: tuple¶
- Abstractmethod:
- Return type:
tuple
The raw data of the result
- property result: Any¶
The result of the metric evaluation
- Return type:
Any
- classmethod result_to_text(result_full)¶
String indicating the evaluation result
- Parameters:
result_full (tuple[float | numpy.floating, Ellipsis]) –
- Return type:
str
- property text¶
The text representation of the evaluation result
- classmethod _file_hash()¶
Calculates a hash value based on the file in which this method was defined.
- Return type:
bytes
- property method_hash: bytes¶
A hash representing the configured metric as a bytes object
- Return type:
bytes
- property method_hash_str: str¶
A hash representing the configured metric as a base64 like string
- Return type:
str
- static result_full_wrapper(func)¶
A decorator for the result_full member function.
Raises an exception if result is accessed on an object that was not applied to data. Caches the result to prevent double calculation.
- class saftig.evaluation.metrics.EvaluationMetricScalar(**kwargs)¶
Bases:
EvaluationMetricParent class for evaluation metrics that yield a scalar value
- property result: float¶
The raw data of the result
- Return type:
float
- classmethod result_to_text(result_full)¶
String indicating the evaluation result
- Parameters:
result_full (tuple[float | numpy.floating, Ellipsis]) –
- Return type:
str
- class saftig.evaluation.metrics.EvaluationMetricPlottable(**kwargs)¶
Bases:
EvaluationMetricParent class for evaluation metrics that provide a plotting feature
- abstract plot(ax)¶
Generate a result plot on the given axes object
- Parameters:
ax (matplotlib.axes.Axes) –
- save_plot(fname, figsize=(6, 3), tight_layout=True)¶
Save the plot to a file
- Parameters:
fname (str | pathlib.Path) –
figsize (tuple[int, int]) –
tight_layout (bool) –
- class saftig.evaluation.metrics.RMSMetric(**kwargs)¶
Bases:
EvaluationMetricScalarThe RMS of the residual signal
- name = 'Residual RMS'¶
- property result_full: tuple[numpy.floating | float]¶
The raw data of the result
- Return type:
tuple[numpy.floating | float]
- static result_to_text(result_full)¶
String indicating the evaluation result
- Parameters:
result_full (tuple[float | numpy.floating, Ellipsis]) –
- Return type:
str
- class saftig.evaluation.metrics.MSEMetric(**kwargs)¶
Bases:
EvaluationMetricScalarThe MSE of the residual signal
- name = 'Residual MSE'¶
- property result_full: tuple[numpy.floating | float]¶
The raw data of the result
- Return type:
tuple[numpy.floating | float]
- class saftig.evaluation.metrics.BandwidthPowerMetric(f_start, f_stop, n_fft=1024, window='hann')¶
Bases:
EvaluationMetricScalarThe signal power on a given frequency range
The spectrum is calculated with welch on each sequence. An average weighted by the sequence length is used to combine spectra from the sequences. The closes bins to f_start and f_stop is chosen as the integration borders.
- Parameters:
f_start (float) – The frequency at which the power integration starts
f_stop (float) – The frequency at which the power integration stops
n_fft (int) – Sample count per FFT block used by welch
window – The FFT window type
- name = 'Residual power on frequency range'¶
- f_start¶
- f_stop¶
- n_fft = 1024¶
- window = 'hann'¶
- property result_full¶
The raw data of the result
- class saftig.evaluation.metrics.PSDMetric(n_fft=1024, window='hann', logx=True, logy=True, show_target=True)¶
Bases:
EvaluationMetricPlottablePlots the PSD of the given signal
The spectrum is calculated with Welch on each sequence. An average weighted by the sequence length is used to combine spectra from the sequences. The closes bins to f_start and f_stop is chosen as the integration borders.
- Parameters:
n_fft (int) – Sample count per FFT block used by Welch’s method
window (str) – fft window type
logx (bool) – Logarithmic x scale
logy (bool) – Logarithmic y scale
show_target (bool) –
- name = 'Power spectral density'¶
- n_fft = 1024¶
- window = 'hann'¶
- logx = True¶
- logy = True¶
- show_target = True¶
- _welch_multiple_sequences(signal)¶
apply welch_multiple_sequences() with correct settings
- Parameters:
signal (collections.abc.Sequence[numpy.typing.NDArray]) –
- property result_full: tuple[numpy.typing.NDArray, numpy.typing.NDArray]¶
The raw data of the result
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray]
- plot(ax)¶
Plot to the given Axes object
- Parameters:
ax (matplotlib.axes.Axes) –