示例#1
0
def test_PAA():
    """Testing 'PAA'."""
    # Parameter
    X = np.arange(30)

    # Test 1
    paa = PAA(window_size=2)
    arr_actual = paa.fit_transform(X[np.newaxis, :])[0]
    arr_desired = np.arange(0.5, 30, 2)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)

    # Test 2
    paa = PAA(window_size=3)
    arr_actual = paa.fit_transform(X[np.newaxis, :])[0]
    arr_desired = np.arange(1, 30, 3)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)

    # Test 3
    paa = PAA(window_size=5)
    arr_actual = paa.fit_transform(X[np.newaxis, :])[0]
    arr_desired = np.arange(2, 30, 5)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)

    # Test 4
    paa = PAA(output_size=10)
    arr_actual = paa.fit_transform(X[np.newaxis, :])[0]
    arr_desired = np.arange(1, 30, 3)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)

    # Test 5
    paa = PAA(window_size=4, overlapping=True)
    arr_actual = paa.fit_transform(X[np.newaxis, :])[0]
    arr_desired = np.array([1.5, 4.5, 8.5, 12.5, 15.5, 19.5, 23.5, 27.5])
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
示例#2
0
 def PAA(self):
     global X_paa
     global a
     try:
         a = int(self.paaline.text())
         paa = PAA(window_size=None, output_size=a, overlapping=True)
         X_paa = paa.transform(X_standardized)
         QMessageBox.information(None, 'Information',
                                 'PAA Applied With Success', QMessageBox.Ok)
     except ValueError:
         QMessageBox.warning(
             None, 'ERROR',
             'Standardize Your Data_set or define how many interval do you want!',
             QMessageBox.Ok)
示例#3
0
 def __init__(self,
              nu=0.5,
              gamma=0.1,
              tol=1e-3,
              degree=3,
              kernel='lcs',
              sax_size=4,
              quantiles='gaussian',
              paa_size=8):
     """
         Constructor accepts some args for sklearn.svm.OneClassSVM and SAX inside.
         Default params are choosen as the most appropriate for flight-anomaly-detection problem
         according the original article.
     """
     self.nu = nu
     self.gamma = gamma
     self.tol = tol
     self.degree = degree
     self.kernel = kernel
     self.stand_scaler = StandardScaler(epsilon=1e-2)
     self.paa = PAA(window_size=None,
                    output_size=paa_size,
                    overlapping=True)
     self.sax = SAX(n_bins=sax_size, quantiles=quantiles)
示例#4
0
import sys

sys.path.append("../")
from utils.utils import *
from pyts.transformation import PAA

sensor = 'tangential_strain'
explosive_point = 80

window_sizes = [4]
for window_size in window_sizes:
    print "_______________________________________________________________________________"
    print "window_size", window_size
    paa = PAA(window_size=window_size, overlapping=True)

    explosion_expert_reader = pd.read_csv(get_raw_path("training"))
    explosion_expert_reader = explosion_expert_reader[explosion_expert_reader.label == 1]
    explosive_train = np.array([np.fromstring(e, dtype=float, sep=',')
                                for e in explosion_expert_reader[sensor]])

    print explosive_train.shape
    explosive_train = paa.transform(explosive_train)
    print explosive_train.shape
    explosive_train = np.array([diff(x) for x in explosive_train])
    print explosive_train.shape

    inflations = []
    deflations = []
    for each in explosive_train:
        inflation = each[:explosive_point/window_size]
        deflation = each[explosive_point/window_size:]
示例#5
0
import numpy as np
from scipy.stats import norm
from pyts.transformation import StandardScaler
from pyts.visualization import plot_standardscaler
from pyts.transformation import PAA
from pyts.visualization import plot_paa

n_samples = 10
n_features = 48
n_classes = 2

rng = np.random.RandomState(41)

delta = 0.5
dt = 1

X = (norm.rvs(scale=delta ** 2 * dt, size=n_samples * n_features, random_state=rng)
     .reshape((n_samples, n_features)))
X[:, 0] = 0
X = np.cumsum(X, axis=1)

y = rng.randint(n_classes, size=n_samples)

standardscaler = StandardScaler(epsilon=1e-2)
X_standardized = standardscaler.transform(X)

plot_standardscaler(X[0])

paa = PAA(window_size=None, output_size=8, overlapping=True)
X_paa = paa.transform(X_standardized)
plot_paa(X_standardized[0], window_size=None, output_size=8, overlapping=True, marker='o')