saftig.evaluation¶
Tooling to automate evaluation of filtering techniques on datasets.
Submodules¶
Classes¶
Generate simple test data for correlated noise mitigation techniques |
Functions¶
|
Calculate the root mean square value of an array |
|
calculate the total power of a signal (square or RMS) |
|
Calculate the ratio between residual power of the residual and the target signal |
|
Calculate the ratio between residual amplitude of the residual and the target signal |
|
Measure the runtime of filers for a specific scenario |
Package Contents¶
- saftig.evaluation.rms(a)¶
Calculate the root mean square value of an array
- Parameters:
a (collections.abc.Sequence | numpy.typing.NDArray) –
- Return type:
float
- saftig.evaluation.total_power(a)¶
calculate the total power of a signal (square or RMS)
>>> import saftig, numpy >>> signal = numpy.ones(10) * 2 >>> saftig.evaluation.total_power(signal) 4.0
- Parameters:
a (collections.abc.Sequence | numpy.typing.NDArray) –
- Return type:
float
- class saftig.evaluation.TestDataGenerator(witness_noise_level=0.1, target_noise_level=0, transfer_function=1, sample_rate=1.0, rng_seed=None)¶
Generate simple test data for correlated noise mitigation techniques The channel count is implicitly defined by the shape of witness_noise_level
- Parameters:
witness_noise_level (float | collections.abc.Sequence) – amplitude ratio of the sensor noise to the correlated noise in the witness sensor Scalar or 1D-vector for multiple sensors
target_noise_level (float) – amplitude ratio of the sensor noise to the correlated noise in the target sensor
transfer_functon – ratio between the amplitude in the target and witness signals
sample_rate (float) – The outputs are referenced to an ASD of 1/sqrt(Hz) if a sample rate is provided
transfer_function (float) –
rng_seed (Optional[int]) –
>>> import saftig as sg >>> # create data with two witness sensors with relative noise amplitudes of 0.1 >>> tdg = sg.evaluation.TestDataGenerator(witness_noise_level=[0.1, 0.1]) >>> # generate a dataset with 1000 samples >>> witness, target = tdg.generate(1000) >>> witness.shape, target.shape ((2, 1000), (1000,))
- rng: Any¶
- witness_noise_level¶
- target_noise_level¶
- transfer_function¶
- sample_rate = 1.0¶
- scaled_whitenoise(shape)¶
Generate whitenoise with an ASD of one
- Parameters:
shape – shape of the new array
- Returns:
Array of white noise
- Return type:
numpy.typing.NDArray
- generate(n)¶
Generate sequences of samples
- Parameters:
N – number of samples
n (int) –
- Returns:
witness signal, target signal
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray]
- saftig.evaluation.residual_power_ratio(target, prediction, start=None, stop=None, remove_dc=True)¶
Calculate the ratio between residual power of the residual and the target signal
- Parameters:
target (collections.abc.Sequence) – target signal array
prediction (collections.abc.Sequence) – prediction array (same length as target
start (int | None) – use only a section of the arrays, start at this index
stop (int | None) – use only a section of the arrays, stop at this index
component (remove DC) – remove DC component before calculation
remove_dc (bool) –
- Return type:
float
- saftig.evaluation.residual_amplitude_ratio(*args, **kwargs)¶
Calculate the ratio between residual amplitude of the residual and the target signal
- Parameters:
target – target signal array
prediction – prediction array (same length as target
start – use only a section of the arrays, start at this index
stop – use only a section of the arrays, stop at this index
component (remove DC) – remove DC component before calculation
- Return type:
float
- saftig.evaluation.measure_runtime(filter_classes, n_samples=int(10000.0), n_filter=128, idx_target=0, n_channel=1, additional_filter_settings=None, repititions=1)¶
Measure the runtime of filers for a specific scenario Be aware that this gives no feedback upon how much multithreading is used!
- Parameters:
n_samples (int) – Length of the test data
n_filter (int) – Length of the FIR filters / input block size
idx_target (int) – Position of the prediction
n_channel (int) – Number of witness sensor channels
additional_filter_settings (collections.abc.Sequence[dict] | None) – optional settings passed to the filters
repititions (int) – how manu repititions to perform during the timing measurement
filter_classes (collections.abc.Sequence[saftig.filtering.FilterBase]) –
- Returns:
(time_conditioning, time_apply) each in seconds
- Return type:
tuple[collections.abc.Sequence, collections.abc.Sequence]