interval_sparsifier#
Removes a given relative amount of samples from a signal.
- class IntervalSparsifier(*kinetic_parameters: tuple[simba_ml.simulation.sparsifier.sparsifier.Sparsifier, Union[int, str]])#
Bases:
SparsifierA Sparsifier that sparsifies intervals with different Sparsifier.
The IntervalSparsifier takes sparsifiers and interval endings as arguments. The sparsifiers are applied to the according intervals.
Inits the IntervalSparsifier.
- Parameters:
*kinetic_parameters – Pairs of (sparsifier, end_of_interval) where the end_of_interval is the last timestep, where the sparsifier should be applied. end_of_interval can either be represented explicit as an integer or relative to the length of the signal as a float.
- Raises:
ValueError – If interval endings are neither ints nor floats in range [0, 1]
TypeError – If Sparsifiers are not of type Sparsifier.
Examples
>>> import pandas as pd >>> from simba_ml.simulation import sparsifier >>> signal = pd.DataFrame({"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) >>> sparsifier.interval_sparsifier.IntervalSparsifier( ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0), 2), ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(1), 7), ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0), 11), ... ).sparsify(signal).sort_index() a 2 3 3 4 4 5 5 6 6 7
>>> sparsifier.interval_sparsifier.IntervalSparsifier( ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0), ... 0.2), ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(1), ... 0.5), ... (sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0), ... 1.0), ... ).sparsify(signal).sort_index() a 2 3 3 4 4 5
- sparsify(signal: DataFrame) DataFrame#
Removes some (1-frac) samples chosen with a uniform random distributions.
- Parameters:
signal – The signal to sparsify.
- Returns:
The sparsified signal.
- Return type:
DataFrame