Skip to content
Snippets Groups Projects
Commit c9a4f4a7 authored by Pierre LOTTE's avatar Pierre LOTTE
Browse files

Frequency anomalies added

parent f75648e3
No related branches found
No related tags found
No related merge requests found
"""
This module provides a frequency anomaly generator class
"""
import numpy as np
from .base import BaseAnomaly
class FrequencyAnomaly(BaseAnomaly):
"""
This class generates and handles its anomaly type
"""
def generate(self):
"""
This function creates and returns the anomaly configuration.
"""
return {
"kind": "FREQUENCY",
"length": int(self.length),
"position": np.random.choice(["start", "middle", "end"]),
"frequency": np.random.uniform(8, 18)
}
"""
This module defines the behavior of a frequency anomaly generator.
"""
from typing import Tuple
import numpy as np
from .base import BaseAnomaly
class FrequencyAnomaly(BaseAnomaly):
"""
This class defines the behavior that every anomaly generator should have.
"""
OSCILLATING_FUNCTIONS = {
"sin": np.sin,
"cos": np.cos,
"versine": lambda x: 1 - np.cos(x),
"vercosine": lambda x: 1 + np.cos(x),
"coversine": lambda x: 1 - np.sin(x),
"covercosine": lambda x: 1 + np.sin(x),
"haversine": lambda x: (1 - np.cos(x)) / 2,
"havercosine": lambda x: (1 + np.cos(x)) / 2,
"hacoversine": lambda x: (1 - np.sin(x)) / 2,
"hacovercosine": lambda x: (1 + np.sin(x)) / 2,
}
def inject(self) -> Tuple[np.array, np.array]:
start, end = self.find_anomaly_index()
dt = .001
res = np.zeros(len(self.data[self.idx]))
self.data[self.idx] = np.zeros(len(self.data[self.idx]))
self.data[self.idx, start:end] = 2 * np.pi * self.params["frequency"] * dt
for term in self.dimension:
func = self.OSCILLATING_FUNCTIONS[term["function"]]
# Generate testing data
signal = self.data[self.idx]
signal += 2 * np.pi * term["frequency"] * dt
signal = func(np.cumsum(signal))
signal *= term["amplitude"]
res += signal
self.data[self.idx] = res
return self.data, self.labels
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment