noisers#

Provides multiple Noisers.

class AdditiveNoiser(distribution: Distribution[float])#

Bases: Noiser

The AdditiveNoiser adds a randomly generated number to elements individually.

The number is generated using a given Distribution.

distribution#

A distribution to generate random noise.

Inits AdditiveNoiser with the provided params.

Parameters:

distribution – A distribution to generate random noise.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Parameters:

signal – The input data.

Returns:

pd.DataFrame

class AdjustingMeanNoiser(weight: Distribution[float])#

Bases: Noiser

The AdjustingMeanNoiser adjusts every value to the mean it’s column.

Does a linear interpolation for each cell between it’s value and it’s columns mean.

With c_{i;j} being an arbitrary cell in column j and m(j)

being the mean of the column j, the following equation holds.

\[c_{i;j} = c_{i_j} + weight * (m(j) + c_{i;j})\]
weight#

Weight of the mean in the linear interpolation.

Example

>>> import pandas as pd
>>> from simba_ml.simulation import distributions
>>> from simba_ml.simulation.noisers.                adjusting_mean_noiser import AdjustingMeanNoiser
>>> clean_signal = pd.DataFrame([0, 10, 50])
>>> clean_signal
    0
0   0
1  10
2  50
>>> noisers = AdjustingMeanNoiser(distributions.Constant(0.5))
>>> noisers.noisify(clean_signal)
    0
0  10
1  15
2  35
>>> noisers = AdjustingMeanNoiser(distributions.Constant(0.2))
>>> noisers.noisify(clean_signal)
    0
0   4
1  12
2  44

Inits the AdjustingMeanNoiser.

Parameters:

weight – Interpolation Factor. When weight is 1, then the output equals the mean of the column. If weight is 0.5 the output equals the mean of the column’s mean and the cell’s value.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Parameters:

signal – The input data.

Returns:

pd.DataFrame

class ColumnNoiser(noisers: dict[str, simba_ml.simulation.noisers.noiser.Noiser])#

Bases: Noiser

The ColumnNoiser applies a different Noiser to every column of the signal.

Columns without a provided Noiser will be skipped.

noisers#

A dictionary containing the column names as keys and the corresponding Noiser as values.

Example

>>> import pandas as pd
>>> from simba_ml.simulation import distributions
>>> from simba_ml.simulation import noisers
>>> clean_signal = pd.DataFrame.from_dict({
...     "A": [75, 52, 68],
...     "B": [33, 96, 64],
...     "C": [57, 5, 13],
...     "D": [65, 4, 51],})
>>> clean_signal
    A   B   C   D
0  75  33  57  65
1  52  96   5   4
2  68  64  13  51
>>> col_noisers = {
...     "A": noisers.AdditiveNoiser(distributions.Constant(2)),
...     "B": noisers.MultiplicativeNoiser(distributions.Constant(2)),
...     "D": noisers.NoNoiser()}
>>> noiser = noisers.ColumnNoiser(col_noisers)
>>> noiser.noisify(clean_signal)
    A    B   C   D
0  77   66  57  65
1  54  192   5   4
2  70  128  13  51

Inits ColumnNoiser with the provided params.

Parameters:

noisers – A dictionary containing the column names as keys and the corresponding Noiser as values.

noisify(signal: DataFrame) DataFrame#

Applies noise to each column individually.

Parameters:

signal – The input data.

Returns:

pd.DataFrame

class ElasticNoiser(k: Distribution[float], invert: bool = False, exponential: bool = False)#

Bases: Noiser

The ElasticNoiser applies noise elastically.

Noise is added randomly at every point using a normal distributions where the variance increases with t.

k#

maximal variance of the normal distributions

invert#

If True, noise is added at the beggining of the curve.

exponential#

If True, uses exponentially increasing noise. If invert = True, exponentially decreasing.

Inits ElasticNoiser with the provided params.

Parameters:
  • k – maximal variance of the normal distributions

  • invert – If True, noise is added at the beggining of the curve.

  • exponential – If True, uses exponentially increasing noise. If invert = True, exponentially decreasing.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Applies random gaussian noise with increasing or decreasing variance over time to the signal.

Parameters:

signal – The input data.

Returns:

pd.DataFrame

Example

>>> import pandas as pd
>>> from simba_ml.simulation import distributions
>>> from simba_ml.simulation.noisers.elastic_noiser import ElasticNoiser
>>> series = [[0]] * 1000
>>> df = pd.DataFrame(series)
>>> df.head()
   0
0  0
1  0
2  0
3  0
4  0
>>> noisers = ElasticNoiser(distributions.Constant(10))
>>> noisers.noisify(df).plot() 
../_images/elastic_noiser_exponential.png
class MultiNoiser(noisers: list[simba_ml.simulation.noisers.noiser.Noiser])#

Bases: Noiser

Applies one randomly selected Noiser to add noise to an input signal.

noisers#

A list of Noiser to choose from.

Inits MultiNoiser with the provided params.

Parameters:

noisers – A list of Noiser to choose from.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Parameters:

signal – The input data.

Returns:

The noised signal.

class MultiplicativeNoiser(distribution: Distribution[float])#

Bases: Noiser

Multiplies each element individually with a randomly generated number.

The number is generated using a selected Distribution.

distribution#

A distribution to generate random noise.

Inits MultiplicativeNoiser with the provided params.

Parameters:

distribution – A distribution to generate random noise.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Parameters:

signal – The input data.

Returns:

pd.DataFrame

class NoNoiser#

Bases: Noiser

The NoNoiser is a dummy Noiser, that applies no noise.

noisify(signal: DataFrame) DataFrame#

Returns the input signal.

Parameters:

signal – The input data.

Returns:

The (unnoised) signal.

class Noiser#

Bases: ABC

A Noiser puts noise to a sample.

abstract noisify(signal: DataFrame) DataFrame#

Noises an incomming signal.

Parameters:

signal – The signal which should be noised.

class SequentialNoiser(noisers: list[simba_ml.simulation.noisers.noiser.Noiser])#

Bases: Noiser

The SequentialNoiser applies multiple given Noiser sequentially.

noisers#

A list of Noiser to be applied.

Inits SequentialNoiser with the provided params.

Parameters:

noisers – A list of Noiser to be applied.

noisify(signal: DataFrame) DataFrame#

Applies noise to the provided signal.

Parameters:

signal – The input data.

Returns:

The noised signal.

simba_ml.simulation.noisers.additive_noiser

Defines the AdditiveNoiser.

simba_ml.simulation.noisers.adjusting_mean_noiser

Defines the ElasticNoiser.

simba_ml.simulation.noisers.column_noiser

Defines the ColumnNoiser.

simba_ml.simulation.noisers.elastic_noiser

Defines the ElasticNoiser.

simba_ml.simulation.noisers.multi_noiser

Defines the MultiNoiser.

simba_ml.simulation.noisers.multiplicative_noiser

Defines the MultiplicativeNoiser.

simba_ml.simulation.noisers.no_noiser

Defines multiple classes for applying noise to a signal.

simba_ml.simulation.noisers.noiser

Defines an abstract definition of Noiser.

simba_ml.simulation.noisers.sequential_noiser

Module providing the SequentialNoiser.