# AnomalySine

Simulate a stream with anomalies in sine waves.

The amount of data generated by this generator is finite.

The data generated corresponds to sine and cosine functions. Anomalies are induced by replacing the cosine values with values from a different a sine function. The `contextual` flag can be used to introduce contextual anomalies which are values in the normal global range, but abnormal compared to the seasonal pattern. Contextual attributes are introduced by replacing cosine entries with sine values.

The target indicates whether or not the instances are anomalous.

## Parameters

- **n\_samples**

  *Type* → `int`

  *Default* → `10000`

  The number of samples to generate. This generator creates a batch of data affected by contextual anomalies and noise.
- **n\_anomalies**

  *Type* → `int`

  *Default* → `2500`

  Number of anomalies. Can't be larger than `n_samples`.
- **contextual**

  *Type* → `bool`

  *Default* → `False`

  If True, will add contextual anomalies.
- **n\_contextual**

  *Type* → `int`

  *Default* → `2500`

  Number of contextual anomalies. Can't be larger than `n_samples`.
- **shift**

  *Type* → `int`

  *Default* → `4`

  Shift in number of samples applied when retrieving contextual anomalies.
- **noise**

  *Type* → `float`

  *Default* → `0.5`

  Amount of noise.
- **replace**

  *Type* → `bool`

  *Default* → `True`

  If True, anomalies are randomly sampled with replacement.
- **seed**

  *Type* → `int | None`

  *Default* → `None`

  Random seed for reproducibility.

## Attributes

- **desc**

  Return the description from the docstring.

## Examples

```python
from river.datasets import synth

dataset = synth.AnomalySine(
    seed=12345,
    n_samples=100,
    n_anomalies=25,
    contextual=True,
    n_contextual=10
)

for x, y in dataset.take(5):
    print(x, y)
```

```text
{'sine': -0.7119, 'cosine': 0.8777} False
{'sine': 0.8792, 'cosine': -0.0290} False
{'sine': 0.0440, 'cosine': 3.0852} True
{'sine': 0.5520, 'cosine': 3.4515} True
{'sine': 0.8037, 'cosine': 0.4027} False
```

## Methods

> [!NOTE]
>
> **take**
>
> Iterate over the k samples.
>
> **Parameters**
>
> - **k** — `int`
