mtsa 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mtsa-0.0.0/PKG-INFO +78 -0
- mtsa-0.0.0/README.md +55 -0
- mtsa-0.0.0/mtsa/__init__.py +8 -0
- mtsa-0.0.0/mtsa/common.py +43 -0
- mtsa-0.0.0/mtsa/correlation_networks.py +39 -0
- mtsa-0.0.0/mtsa/experiments.py +22 -0
- mtsa-0.0.0/mtsa/features/__init__.py +7 -0
- mtsa-0.0.0/mtsa/features/mel.py +96 -0
- mtsa-0.0.0/mtsa/features/stats.py +375 -0
- mtsa-0.0.0/mtsa/metrics.py +7 -0
- mtsa-0.0.0/mtsa/model_selection.py +68 -0
- mtsa-0.0.0/mtsa/models/GANF_components/DROCC.py +217 -0
- mtsa-0.0.0/mtsa/models/GANF_components/DeepSAD.py +429 -0
- mtsa-0.0.0/mtsa/models/GANF_components/GAN.py +307 -0
- mtsa-0.0.0/mtsa/models/GANF_components/NF.py +426 -0
- mtsa-0.0.0/mtsa/models/GANF_components/RNN.py +103 -0
- mtsa-0.0.0/mtsa/models/GANF_components/__init__.py +0 -0
- mtsa-0.0.0/mtsa/models/GANF_components/gacvaeBaseModel.py +309 -0
- mtsa-0.0.0/mtsa/models/GANF_components/ganfBaseModel.py +268 -0
- mtsa-0.0.0/mtsa/models/GANF_components/ganfLayoutData.py +37 -0
- mtsa-0.0.0/mtsa/models/GANF_components/gnn.py +24 -0
- mtsa-0.0.0/mtsa/models/GANF_components/vae.py +55 -0
- mtsa-0.0.0/mtsa/models/__init__.py +19 -0
- mtsa-0.0.0/mtsa/models/base.py +0 -0
- mtsa-0.0.0/mtsa/models/gacvae.py +138 -0
- mtsa-0.0.0/mtsa/models/ganf.py +155 -0
- mtsa-0.0.0/mtsa/models/hitachi.py +232 -0
- mtsa-0.0.0/mtsa/models/isolationforest.py +200 -0
- mtsa-0.0.0/mtsa/models/mfccmix.py +79 -0
- mtsa-0.0.0/mtsa/models/networkAnalysis/__init__.py +0 -0
- mtsa-0.0.0/mtsa/models/networkAnalysis/networkLearnerModel.py +64 -0
- mtsa-0.0.0/mtsa/models/networkAnalysis/networkLearnerModelResultOrchestrator.py +30 -0
- mtsa-0.0.0/mtsa/models/networkAnalysis/networkLearnerObserver.py +77 -0
- mtsa-0.0.0/mtsa/models/oneClassSVM.py +84 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/__init__.py +0 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/decoder.py +34 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/encoder.py +28 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/exceptions/__init__.py +0 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/exceptions/parametererror.py +5 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/frequencycoder.py +22 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/rancoders.py +90 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/ransyncoders_base.py +554 -0
- mtsa-0.0.0/mtsa/models/ransyncoders_components/sinusoidalcoder.py +43 -0
- mtsa-0.0.0/mtsa/models/ransyncorders.py +165 -0
- mtsa-0.0.0/mtsa/pipelines.py +92 -0
- mtsa-0.0.0/mtsa/plotters.py +275 -0
- mtsa-0.0.0/mtsa/training.py +0 -0
- mtsa-0.0.0/mtsa/utils.py +138 -0
- mtsa-0.0.0/mtsa.egg-info/PKG-INFO +78 -0
- mtsa-0.0.0/mtsa.egg-info/SOURCES.txt +63 -0
- mtsa-0.0.0/mtsa.egg-info/dependency_links.txt +1 -0
- mtsa-0.0.0/mtsa.egg-info/requires.txt +10 -0
- mtsa-0.0.0/mtsa.egg-info/top_level.txt +2 -0
- mtsa-0.0.0/mtsa.egg-info/zip-safe +1 -0
- mtsa-0.0.0/pyproject.toml +3 -0
- mtsa-0.0.0/setup.cfg +37 -0
- mtsa-0.0.0/tests/__init__.py +0 -0
- mtsa-0.0.0/tests/experimental_setup.py +225 -0
- mtsa-0.0.0/tests/test_DCASE2020_task2.py +20 -0
- mtsa-0.0.0/tests/test_beam_read.py +33 -0
- mtsa-0.0.0/tests/test_beam_write.py +36 -0
- mtsa-0.0.0/tests/test_hitachi.py +19 -0
- mtsa-0.0.0/tests/test_jsonappen.py +8 -0
- mtsa-0.0.0/tests/test_mfccmix.py +19 -0
mtsa-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mtsa
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Multiple Time Series Analysis
|
|
5
|
+
Home-page: https://github.com/diegompin/mtsa
|
|
6
|
+
Author: Diego Pinheiro
|
|
7
|
+
Author-email: diegompin@gmail.com
|
|
8
|
+
License: BSD 3-Clause License
|
|
9
|
+
Keywords: mtsa,setuptools
|
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: pandas==2.2.2
|
|
14
|
+
Requires-Dist: pytest==7.2.0
|
|
15
|
+
Requires-Dist: numpy==1.24.4
|
|
16
|
+
Requires-Dist: matplotlib==3.8.0
|
|
17
|
+
Requires-Dist: scipy==1.11.2
|
|
18
|
+
Requires-Dist: ipykernel==5.5.6
|
|
19
|
+
Requires-Dist: librosa==0.9.2
|
|
20
|
+
Requires-Dist: tensorflow==2.17.0
|
|
21
|
+
Requires-Dist: spectrum==0.6.8
|
|
22
|
+
Requires-Dist: torch==2.5.1
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<img width="805" height="310" alt="image" src="https://github.com/user-attachments/assets/6f0ff77f-c83e-45eb-bdf6-b6f2fcbd31ed" />
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
MTSA is a research toolkit designed to aggregate machine learning models for anomaly detection, with a strong focus on enhancing reproducibility and explainability in model implementation. It offers a structured environment for developing, testing, and comparing various anomaly detection approaches, prioritizing replicability and ease of use. The toolkit is continuously updated to include both classical and state-of-the-art algorithms for anomaly detection in multivariate time series.
|
|
29
|
+
|
|
30
|
+
## 🔧 Installation
|
|
31
|
+
|
|
32
|
+
To get started, clone the repository and install the required dependencies:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/your-username/MTSA.git
|
|
36
|
+
cd MTSA
|
|
37
|
+
pip install -r requirements.txt
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 🚀 Usage
|
|
41
|
+
|
|
42
|
+
MTSA allows you to run anomaly detection models on acoustic data collected from complex systems like industrial machines.
|
|
43
|
+
|
|
44
|
+
A complete example is available in the following Jupyter notebook:
|
|
45
|
+
👉 [examples/MTSA.ipynb](examples/MTSA.ipynb)
|
|
46
|
+
|
|
47
|
+
> **Note:** If you encounter issues while running on Google Colab, try upgrading the Colab package:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install --upgrade google-colab
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 🧠 Implemented Machine Learning Approaches
|
|
54
|
+
|
|
55
|
+
MTSA currently integrates the following anomaly detection models:
|
|
56
|
+
|
|
57
|
+
- **Hitachi**
|
|
58
|
+
A robust autoencoder model specifically designed for industrial anomaly detection tasks.
|
|
59
|
+
|
|
60
|
+
- **RANSynCoders**
|
|
61
|
+
Ensemble of autoencoders with FFT, leveraging bootstrapping to perform robust anomaly inference.
|
|
62
|
+
|
|
63
|
+
- **GANF**
|
|
64
|
+
A model that combines graph structures, recurrent neural networks (RNNs), and normalizing flows to perform anomaly inference.
|
|
65
|
+
|
|
66
|
+
- **Isolation Forest**
|
|
67
|
+
A tree-based ensemble method that isolates anomalies.
|
|
68
|
+
|
|
69
|
+
- **OSVM (One-Class SVM)**
|
|
70
|
+
A support vector-based approach for detecting outliers by modeling the distribution of normal data.
|
|
71
|
+
|
|
72
|
+
And more!
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## 🌐 Learn More
|
|
76
|
+
|
|
77
|
+
For full documentation, examples, and additional resources, visit our [official website](https://iotdataatelier.github.io/mtsa-docs/).
|
|
78
|
+
|
mtsa-0.0.0/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="805" height="310" alt="image" src="https://github.com/user-attachments/assets/6f0ff77f-c83e-45eb-bdf6-b6f2fcbd31ed" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
MTSA is a research toolkit designed to aggregate machine learning models for anomaly detection, with a strong focus on enhancing reproducibility and explainability in model implementation. It offers a structured environment for developing, testing, and comparing various anomaly detection approaches, prioritizing replicability and ease of use. The toolkit is continuously updated to include both classical and state-of-the-art algorithms for anomaly detection in multivariate time series.
|
|
6
|
+
|
|
7
|
+
## 🔧 Installation
|
|
8
|
+
|
|
9
|
+
To get started, clone the repository and install the required dependencies:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/your-username/MTSA.git
|
|
13
|
+
cd MTSA
|
|
14
|
+
pip install -r requirements.txt
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 🚀 Usage
|
|
18
|
+
|
|
19
|
+
MTSA allows you to run anomaly detection models on acoustic data collected from complex systems like industrial machines.
|
|
20
|
+
|
|
21
|
+
A complete example is available in the following Jupyter notebook:
|
|
22
|
+
👉 [examples/MTSA.ipynb](examples/MTSA.ipynb)
|
|
23
|
+
|
|
24
|
+
> **Note:** If you encounter issues while running on Google Colab, try upgrading the Colab package:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install --upgrade google-colab
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🧠 Implemented Machine Learning Approaches
|
|
31
|
+
|
|
32
|
+
MTSA currently integrates the following anomaly detection models:
|
|
33
|
+
|
|
34
|
+
- **Hitachi**
|
|
35
|
+
A robust autoencoder model specifically designed for industrial anomaly detection tasks.
|
|
36
|
+
|
|
37
|
+
- **RANSynCoders**
|
|
38
|
+
Ensemble of autoencoders with FFT, leveraging bootstrapping to perform robust anomaly inference.
|
|
39
|
+
|
|
40
|
+
- **GANF**
|
|
41
|
+
A model that combines graph structures, recurrent neural networks (RNNs), and normalizing flows to perform anomaly inference.
|
|
42
|
+
|
|
43
|
+
- **Isolation Forest**
|
|
44
|
+
A tree-based ensemble method that isolates anomalies.
|
|
45
|
+
|
|
46
|
+
- **OSVM (One-Class SVM)**
|
|
47
|
+
A support vector-based approach for detecting outliers by modeling the distribution of normal data.
|
|
48
|
+
|
|
49
|
+
And more!
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## 🌐 Learn More
|
|
53
|
+
|
|
54
|
+
For full documentation, examples, and additional resources, visit our [official website](https://iotdataatelier.github.io/mtsa-docs/).
|
|
55
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from functools import partial
|
|
3
|
+
from functools import reduce
|
|
4
|
+
from mtsa.experiments import *
|
|
5
|
+
|
|
6
|
+
def elapsed_time(fun, *args) -> Result:
|
|
7
|
+
start = time.time()
|
|
8
|
+
fun_return = fun(*args)
|
|
9
|
+
end = time.time()
|
|
10
|
+
time_elapsed = end - start
|
|
11
|
+
result = Result(time_elapsed, fun_return)
|
|
12
|
+
return result
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def multiple_runs(runs, fun, *args):
|
|
16
|
+
list_run_ids = range(runs)
|
|
17
|
+
multiple_results = map(
|
|
18
|
+
lambda run_id:
|
|
19
|
+
{
|
|
20
|
+
'run_id': run_id,
|
|
21
|
+
"run_details": elapsed_time(fun, *args)
|
|
22
|
+
},
|
|
23
|
+
list_run_ids
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return list(multiple_results)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import functools as ft
|
|
31
|
+
def print(element):
|
|
32
|
+
#TODO this is ugly but leting keras to be serialized causes circular reference at json.dumps
|
|
33
|
+
should_dump = lambda o: any(map(ft.partial(isinstance, o), [t for t in [int, float, str, ParamResult, Result, Params, ModelParam]]))
|
|
34
|
+
def default(o):
|
|
35
|
+
if should_dump(o):
|
|
36
|
+
if hasattr(o, "__dict__"):
|
|
37
|
+
return o.__dict__
|
|
38
|
+
else:
|
|
39
|
+
return str(o)
|
|
40
|
+
else:
|
|
41
|
+
return ""
|
|
42
|
+
json_data = json.dumps(element, indent=4, default=default)
|
|
43
|
+
return json
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import abc
|
|
3
|
+
|
|
4
|
+
class CorrelationNetwork(abc.ABC):
|
|
5
|
+
"""
|
|
6
|
+
Base class for implementing correlation between mfccs
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def get_correlation(self, X: np.ndarray):
|
|
10
|
+
"""Implement correlation"""
|
|
11
|
+
|
|
12
|
+
class PearsonCorrelationNetwork(CorrelationNetwork):
|
|
13
|
+
|
|
14
|
+
def get_correlation(self, X : np.ndarray):
|
|
15
|
+
C = np.corrcoef(X, rowvar=True)
|
|
16
|
+
return C
|
|
17
|
+
|
|
18
|
+
class DynamicCorrelationNetwork(CorrelationNetwork):
|
|
19
|
+
|
|
20
|
+
def get_correlation(self, X : np.ndarray):
|
|
21
|
+
"""
|
|
22
|
+
Calculate dynamic correlation <(i - <i>)(j - <j>)>
|
|
23
|
+
where <x> is the first moment (e.g, expected value)
|
|
24
|
+
"""
|
|
25
|
+
X = X.T
|
|
26
|
+
x_min = np.min(X, axis=0)
|
|
27
|
+
x_max = np.max(X, axis=0)
|
|
28
|
+
X = (X - x_min) / (x_max - x_min)
|
|
29
|
+
X = 2*X - 1
|
|
30
|
+
m = np.mean(X, axis=0)
|
|
31
|
+
D = X - m
|
|
32
|
+
return 1/len(D) * D.T.dot(D)
|
|
33
|
+
|
|
34
|
+
import scipy.stats as st
|
|
35
|
+
class SpearmanCorrelationNetwork(CorrelationNetwork):
|
|
36
|
+
|
|
37
|
+
def get_correlation(self, X : np.ndarray):
|
|
38
|
+
rho, pval = st.spearmanr(X)
|
|
39
|
+
return rho
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class ModelParam:
|
|
6
|
+
name: str
|
|
7
|
+
obj: object
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Params:
|
|
11
|
+
path: str
|
|
12
|
+
model: ModelParam
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class Result:
|
|
16
|
+
time_elapsed: float
|
|
17
|
+
fun_return: object
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class ParamResult:
|
|
21
|
+
params: Params
|
|
22
|
+
result: Result
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Base classes for all mfcc estimators."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import sys
|
|
5
|
+
from sklearn.base import BaseEstimator, TransformerMixin
|
|
6
|
+
import scipy.stats as st
|
|
7
|
+
import librosa as lib
|
|
8
|
+
from functools import reduce
|
|
9
|
+
|
|
10
|
+
class Array2MelSpec(BaseEstimator, TransformerMixin):
|
|
11
|
+
def __init__(self,
|
|
12
|
+
sampling_rate,
|
|
13
|
+
n_fft,
|
|
14
|
+
hop_length,
|
|
15
|
+
n_mels,
|
|
16
|
+
frames,
|
|
17
|
+
power
|
|
18
|
+
):
|
|
19
|
+
self.sampling_rate = sampling_rate
|
|
20
|
+
self.n_fft = n_fft
|
|
21
|
+
self.hop_length = hop_length
|
|
22
|
+
self.n_mels = n_mels
|
|
23
|
+
self.frames = frames
|
|
24
|
+
self.power = power
|
|
25
|
+
|
|
26
|
+
def fit(self, X, y=None, **fit_params):
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
def transform(self, X, y=None, **fit_params):
|
|
30
|
+
|
|
31
|
+
def normalize_melspec(mel_spectrogram):
|
|
32
|
+
|
|
33
|
+
# 03 convert melspectrogram to log mel energy
|
|
34
|
+
log_mel_spectrogram = 20.0 / self.power * np.log10(mel_spectrogram + sys.float_info.epsilon)
|
|
35
|
+
|
|
36
|
+
# 04 calculate total vector size
|
|
37
|
+
vectorarray_size = len(log_mel_spectrogram[0, :]) - self.frames + 1
|
|
38
|
+
|
|
39
|
+
# 05 skip too short clips
|
|
40
|
+
if vectorarray_size < 1:
|
|
41
|
+
return np.empty((0, dims), float)
|
|
42
|
+
|
|
43
|
+
# 06 generate feature vectors by concatenating multi_frames
|
|
44
|
+
dims = self.n_mels * self.frames
|
|
45
|
+
vectorarray = np.zeros((vectorarray_size, dims), float)
|
|
46
|
+
for t in range(self.frames):
|
|
47
|
+
vectorarray[:, self.n_mels * t: self.n_mels * (t + 1)] = log_mel_spectrogram[:, t: t + vectorarray_size].T
|
|
48
|
+
|
|
49
|
+
return vectorarray
|
|
50
|
+
|
|
51
|
+
def extract_melspec(y):
|
|
52
|
+
params = {
|
|
53
|
+
'y':y,
|
|
54
|
+
'n_fft': self.n_fft,
|
|
55
|
+
'hop_length': self.hop_length,
|
|
56
|
+
"n_mels": self.n_mels,
|
|
57
|
+
"power": self.power
|
|
58
|
+
}
|
|
59
|
+
if self.sampling_rate:
|
|
60
|
+
params['sr']=self.sampling_rate
|
|
61
|
+
|
|
62
|
+
mel_spectrogram = lib.feature.melspectrogram(**params)
|
|
63
|
+
|
|
64
|
+
normalized_melspec = normalize_melspec(mel_spectrogram)
|
|
65
|
+
|
|
66
|
+
return normalized_melspec
|
|
67
|
+
Xt = np.array(
|
|
68
|
+
reduce(
|
|
69
|
+
lambda n1, n2: np.concatenate([n1,n2]),
|
|
70
|
+
map(extract_melspec, X))
|
|
71
|
+
)
|
|
72
|
+
return Xt
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Array2Mfcc(BaseEstimator, TransformerMixin):
|
|
76
|
+
"""
|
|
77
|
+
Gets a numpy array containing audio signals and transforms it into a numpy array containing mfcc signals
|
|
78
|
+
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def __init__(self, sampling_rate):
|
|
82
|
+
self.sampling_rate = sampling_rate
|
|
83
|
+
#self.n_mfcc = n_mfcc
|
|
84
|
+
|
|
85
|
+
def fit(self, X, y=None, **fit_params):
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def transform(self, X, y=None, **fit_params):
|
|
89
|
+
def extract_mfcc(y):
|
|
90
|
+
if self.sampling_rate:
|
|
91
|
+
return lib.feature.mfcc(y=y, sr=self.sampling_rate)
|
|
92
|
+
else:
|
|
93
|
+
return lib.feature.mfcc(y=y)
|
|
94
|
+
Xt = np.array(list(map(extract_mfcc, X)))
|
|
95
|
+
return Xt
|
|
96
|
+
|