keep_extreme_values_sparsifier#

Removes a given relative amount of samples from a signal.

class KeepExtremeValuesSparsifier(sparsifier: Sparsifier, lower_bound: float = 0.1, upper_bound: float = 0.1)#

Bases: Sparsifier

A Sparsifier that keeps extreme values.

Inits the KeepExtremeValuesSparsifier.

Parameters:
  • sparsifier – The sparsifier to apply to the signal.

  • lower_bound – The fraction of timestamps to keep because the values is in the lower bound.

  • upper_bound – The fraction of timestamps to keep because the values is in the upper bound.

Raises:
  • ValueError – lower_bound or upper_bound is not in range [0, 1] or lower_bound > upper_bound.

  • TypeError – lower_bound or upper_bound is not a float.

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.keep_extreme_values_sparsifier.KeepExtremeValuesSparsifier(
...     sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0)
... ).sparsify(signal).sort_index()
    a
0   1
9  10
>>> signal = pd.DataFrame({
...     "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
...     "b": [1, 3, 5, 7, 9, 10, 8, 6, 5, 2]})
>>> sparsifier.keep_extreme_values_sparsifier.KeepExtremeValuesSparsifier(
...     sparsifier.random_sample_sparsifier.RandomSampleSparsifier(0),
... ).sparsify(signal).sort_index()
    a   b
0   1   1
5   6  10
9  10   2
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