-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
81 lines (61 loc) · 2.24 KB
/
Copy pathutils.py
File metadata and controls
81 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
import os
from sklearn.preprocessing import LabelEncoder
def create_directory(directory_path):
"""Create a non-existing directory.
Parameters
----------
directory_path: str
The directory to be created if non existing.
Returns
-------
None.
"""
if not os.path.isdir(directory_path):
os.mkdir(directory_path)
def encode_labels(y):
"""Encode labels.
Parameters
----------
y: np.ndarray
The input labels of shape (n_instances)
Returns
-------
np.ndarray of shape (n_instances)
The output labels encoded using sklearn.
"""
labenc = LabelEncoder()
return labenc.fit_transform(y)
def znormalisation(x):
"""Z-Normalize the input time series on the time axis.
Parameters
----------
x: np.ndarray
The input time series dataset of shape:
(n_instances, n_channels, n_timepoints).
Returns
-------
np.ndarray of shape (n_instances, n_channels, n_timepoints)
The z-normalized version of x on the time axis.
"""
stds = np.std(x, axis=2, keepdims=True)
if len(stds[stds == 0.0]) > 0:
stds[stds == 0.0] = 1.0
return (x - x.mean(axis=2, keepdims=True)) / stds
return (x - x.mean(axis=2, keepdims=True)) / (x.std(axis=2, keepdims=True))
def _get_distance_params(args):
distance_params = {}
if args.distance == "dtw" or args.distance == "ddtw":
distance_params["window"] = args.distance_params.window
distance_params["itakura_max_slope"] = args.distance_params.itakura_max_slope
elif args.distance == "shape_dtw":
distance_params["window"] = args.distance_params.window
distance_params["itakura_max_slope"] = args.distance_params.itakura_max_slope
distance_params["descriptor"] = args.distance_params.descriptor
distance_params["reach"] = args.distance_params.reach
elif args.distance == "msm":
distance_params["window"] = args.distance_params.window
distance_params["itakura_max_slope"] = args.distance_params.itakura_max_slope
distance_params["independent"] = args.distance_params.independent
distance_params["c"] = args.distance_params.c
return distance_params