Commit 304d6f3f authored by Antoine Guillaume's avatar Antoine Guillaume

Adding subwindow approach support

parent e3496cd6
This diff is collapsed.
......@@ -34,6 +34,12 @@ Configuration parameters are located at the beginning of CV_script, you MUST cha
To change or check the algorithms parameters, they all are redefined in custom wrapper classes to avoid errors, if a parameter is not specified in the constructor, it is left as default.
The representations methods are defined inside utils.representations and the classifications methods inside utils.classifications.
To change the parameter of TS-CHIEF, you can change the values of the following arguments in the ts-chief script:
```bash
-trees="300" -s="ee:4,boss:50,rise:50"
```
If you want to give more predictive power to this algorithm, increasing the number of trees and the number of random split generated by each method (boss, rise, ...) is the way to go. We used those value to avoid memory errors, the shorter the input time series, the higher those values can be without causing trouble.
## Usage
Extract the files of the dataset archive located in ~/datasets in the dataset folder
......@@ -74,8 +80,6 @@ by
from sktime.utils.data_container import tabularize, from_3d_numpy_to_nested
```
* We also modified InceptionTime to use binary_crossentropy (change loss name and use sigmod layer with 1 neuron as an output) and weighted accuracy for early stopping. This is not mandatory but is more suited to our problem.
## Contributing
If any bug should occur, please open a issue so we can work on a fix !
......
#!/bin/bash
n_cv=9
n_r=4
size=1000
size=1513
for id_r in `seq 1 $n_r`
do
for id_cv in `seq 0 $n_cv`
do
jdk/jdk-15/bin/java -jar tschief.jar -train="datasets/TSCHIEF/data_Train_"$size"_"$id_cv"_R"$id_r".csv" -test="datasets/TSCHIEF/data_Test_"$size"_"$id_cv"_R"$id_r".csv" -out="results/TSCHIEF/" -repeats="1" -trees="500" -s="ee:10,boss:150,rise:150" -export="1" -verbosity="1" -shuffle="True" -target_column="last"
jdk/jdk-15/bin/java -Xms6G -Xmx12G -jar tschief.jar -train="datasets/TSCHIEF/data_Train_"$size"_"$id_cv"_R"$id_r".csv" -test="datasets/TSCHIEF/data_Test_"$size"_"$id_cv"_R"$id_r".csv" -out="results/TSCHIEF/" -repeats="1" -trees="300" -s="ee:4,boss:50,rise:50" -export="1" -verbosity="1" -shuffle="True" -target_column="last"
done
done
This diff is collapsed.
......@@ -13,17 +13,17 @@ from matplotlib import pyplot as plt
from sklearn.base import BaseEstimator, TransformerMixin
# # Define classes for representation methods
# Here we define custom classes when necessary for the representation methods we will use inside pipelines during cross validation.
#
# Here we define custom classes when necessary for the representation methods we will use inside pipelines during cross validation.
#
# See corresponding modules documentation for documentation.
#
#
# Pyts : https://pyts.readthedocs.io/
#
#
# MatrixProfile : https://matrixprofile.docs.matrixprofile.org/
# In[2]:
#Gramian natively use PAA, reccurence don't,
#Gramian natively use PAA, reccurence don't,
#that's why you'll see calls to PAA inside the Recurrence class but not in the Gramian
class Gramian_transform(BaseEstimator, TransformerMixin):
......@@ -33,11 +33,11 @@ class Gramian_transform(BaseEstimator, TransformerMixin):
self.method = method
self.cmap = plt.get_cmap('jet')
self.transformer = None
def transform(self, X, y=None):
if type(X[0]) == pd.core.series.Series:
X = np.asarray([x.values for x in X])
X = np.asarray([self.transformer.transform(x.reshape(1,-1)) for x in X if x.shape[0] >= self.img_size])
if self.flatten == True:
X = X.reshape(X.shape[0], X.shape[2])
......@@ -45,14 +45,14 @@ class Gramian_transform(BaseEstimator, TransformerMixin):
X = X.reshape(X.shape[0], self.img_size, self.img_size, 1)
X = self.cmap(X)[:,:,:,:,0:3].reshape(X.shape[0],self.img_size, self.img_size,3)
return X
def fit(self, X, y=None):
self.transformer = GramianAngularField(image_size=self.img_size,
method=self.method,
flatten=self.flatten)
self.transformer.fit(X)
return self
class Recurrence_transform(BaseEstimator, TransformerMixin):
def __init__(self, output_size=128, dimension=1, time_delay=6, flatten=False):
self.output_size = output_size
......@@ -61,11 +61,11 @@ class Recurrence_transform(BaseEstimator, TransformerMixin):
self.time_delay = time_delay
self.cmap = plt.get_cmap('jet')
self.transformer = None
def transform(self, X, y=None):
if type(X[0]) == pd.core.series.Series:
X = np.asarray([x.values for x in X])
X = np.asarray([self.approximator.transform(x.reshape(1,-1))for x in X if x.shape[0] >= self.output_size])
X = np.asarray([self.transformer.transform(x) for x in X if x.shape[0]])
if self.flatten == True:
......@@ -77,7 +77,7 @@ class Recurrence_transform(BaseEstimator, TransformerMixin):
def fit(self, X, y=None):
self.approximator = PiecewiseAggregateApproximation(output_size=self.output_size,
window_size=None,
window_size=None,
overlapping=False)
self.approximator.fit(X)
self.transformer = RecurrencePlot(dimension=self.dimension,
......@@ -85,51 +85,51 @@ class Recurrence_transform(BaseEstimator, TransformerMixin):
flatten=self.flatten)
self.transformer.fit(X)
return self
class PiecewiseApproximation_transform(BaseEstimator, TransformerMixin):
def __init__(self, output_size=1000, overlapping=False, window_size=None):
self.output_size = output_size
self.overlapping = overlapping
self.window_size = window_size
self.transformer = None
def transform(self, X, y=None):
if type(X[0]) == pd.core.series.Series:
X = np.asarray([x.values for x in X])
X = np.asarray([self.transformer.transform(x.reshape(1,-1)) for x in X if x.shape[0] >= self.output_size])
X = X.reshape(X.shape[0], X.shape[2], X.shape[1])
return X
def fit(self, X, y=None):
self.transformer = PiecewiseAggregateApproximation(output_size=self.output_size,
self.transformer = PiecewiseAggregateApproximation(output_size=self.output_size,
window_size=self.window_size,
overlapping=self.overlapping)
self.transformer.fit(X)
return self
class SymbolicAggregate_transform(BaseEstimator, TransformerMixin):
def __init__(self, n_bins=7, strategy='uniform', alphabet='ordinal'):
def __init__(self, n_bins=5, strategy='uniform', alphabet='ordinal'):
self.n_bins = n_bins
self.strategy = strategy
self.alphabet = alphabet
self.transformer = None
def transform(self, X, y=None):
X = np.asarray([self.transformer.transform(x.reshape(1,-1)).astype(float) if np.max(x) - np.min(x) != 0 else np.zeros((1,x.shape[0])) for x in X])
X = X.reshape(X.shape[0], X.shape[2], X.shape[1])
return X
def fit(self, X, y=None):
self.transformer = SymbolicAggregateApproximation(n_bins=self.n_bins,
strategy=self.strategy,
alphabet=self.alphabet)
self.transformer.fit(X)
return self
class SymbolicFourrier_transform(BaseEstimator, TransformerMixin):
def __init__(self, n_coefs=20, n_bins=7, strategy='uniform', drop_sum=False,
anova=True, norm_mean=True, norm_std=False, alphabet='ordinal'):
def __init__(self, n_coefs=10, n_bins=5, strategy='uniform', drop_sum=True,
anova=True, norm_mean=False, norm_std=False, alphabet='ordinal'):
self.n_coefs = n_coefs
self.n_bins = n_bins
self.strategy = strategy
......@@ -139,12 +139,12 @@ class SymbolicFourrier_transform(BaseEstimator, TransformerMixin):
self.norm_mean = norm_mean
self.norm_std = norm_std
self.transformer = None
def transform(self, X, y=None):
X = np.asarray([self.transformer.transform(x.reshape(1,-1)).astype(float) if np.max(x) - np.min(x) != 0 else np.zeros((1,x.shape[0])) for x in X])
X = np.asarray([self.transformer.transform(x.reshape(1,-1)).astype(float) if np.max(x) - np.min(x) != 0 else np.zeros((1,x.shape[0])) for x in X])
X = X.reshape(X.shape[0], X.shape[2], X.shape[1])
return X
def fit(self, X, y):
self.transformer = SymbolicFourierApproximation(n_coefs=self.n_coefs, n_bins=self.n_bins,
strategy=self.strategy, alphabet=self.alphabet,
......@@ -153,24 +153,24 @@ class SymbolicFourrier_transform(BaseEstimator, TransformerMixin):
X = X.reshape(X.shape[0],X.shape[1])
self.transformer.fit(X,y)
return self
class MatrixProfile_transform():
def __init__(self, window_size=0.075):
def __init__(self, window_size=0.15):
self.window_size = window_size
def transform(self, X, y=None):
if type(X[0]) == pd.core.series.Series:
X = np.asarray([x.values for x in X])
X = np.asarray([mp.compute(x.reshape(-1),windows=x.shape[0]*self.window_size)['mp'].reshape(1,-1) for x in X])
X = np.asarray([mp.compute(x.reshape(-1),windows=x.shape[0]*self.window_size)['mp'].reshape(1,-1) for x in X])
X = X.reshape(X.shape[0], X.shape[2], X.shape[1])
return X
def fit(self, X, y=None):
return self
class ROCKET_transform(BaseEstimator, TransformerMixin):
def __init__(self, n_kernels=15000, kernel_sizes=(5,7,9), flatten=False):
def __init__(self, n_kernels=20000, kernel_sizes=(5,7,9,11), flatten=False):
self.flatten = flatten
self.n_kernels = n_kernels
self.kernel_sizes = kernel_sizes
......@@ -184,7 +184,7 @@ class ROCKET_transform(BaseEstimator, TransformerMixin):
else:
X = X.reshape(X.shape[0], X.shape[1], 1)
return X
def fit(self, X, y=None):
self.transformer = ROCKET(n_kernels=self.n_kernels, kernel_sizes=self.kernel_sizes)
X = X.reshape(X.shape[0],X.shape[1])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment