├── .idea
├── Pre-process.iml
├── inspectionProfiles
│ └── profiles_settings.xml
├── modules.xml
└── vcs.xml
├── Basis_Devices
├── Basis_Device_PreprocessingEDA.Rmd
└── README.md
├── Complete - Browse file.ipynb
├── Complete - User path.ipynb
├── Empatica_E4
└── E4FileFormatter.ipynb
├── README.md
├── Signal-Alignment
├── .idea
│ ├── .gitignore
│ ├── Signal-Alignment.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── other.xml
│ └── vcs.xml
├── README.md
├── __pycache__
│ └── dtw.cpython-37.pyc
├── csv
│ ├── 19-005AW.csv
│ ├── 19-005ECG.csv
│ └── result.csv
├── data
│ ├── 50words_TRAIN
│ ├── Adiac_TRAIN
│ ├── ArrowHead_TRAIN
│ ├── Beef_TRAIN
│ ├── BeetleFly_TRAIN
│ ├── BirdChicken_TRAIN
│ ├── CBF_TRAIN
│ ├── Car_TRAIN
│ ├── ChlorineConcentration_TRAIN
│ ├── CinC_ECG_torso_TRAIN
│ ├── Coffee_TRAIN
│ ├── Computers_TRAIN
│ ├── Cricket_X_TRAIN
│ ├── Cricket_Y_TRAIN
│ ├── Cricket_Z_TRAIN
│ ├── DiatomSizeReduction_TRAIN
│ ├── DistalPhalanxOutlineAgeGroup_TRAIN
│ ├── DistalPhalanxOutlineCorrect_TRAIN
│ ├── DistalPhalanxTW_TRAIN
│ ├── ECG200_TRAIN
│ ├── ECG5000_TRAIN
│ ├── ECGFiveDays_TRAIN
│ ├── Earthquakes_TRAIN
│ ├── ElectricDevices_TRAIN
│ ├── FISH_TRAIN
│ ├── FaceAll_TRAIN
│ ├── FaceFour_TRAIN
│ ├── FacesUCR_TRAIN
│ ├── FordA_TRAIN
│ ├── FordB_TRAIN
│ ├── Gun_Point_TRAIN
│ ├── Ham_TRAIN
│ ├── HandOutlines_TRAIN
│ ├── Haptics_TRAIN
│ ├── Herring_TRAIN
│ ├── InlineSkate_TRAIN
│ ├── InsectWingbeatSound_TRAIN
│ ├── ItalyPowerDemand_TRAIN
│ ├── LargeKitchenAppliances_TRAIN
│ ├── Lighting2_TRAIN
│ ├── Lighting7_TRAIN
│ ├── MALLAT_TRAIN
│ ├── Meat_TRAIN
│ ├── MedicalImages_TRAIN
│ ├── MiddlePhalanxOutlineAgeGroup_TRAIN
│ ├── MiddlePhalanxOutlineCorrect_TRAIN
│ ├── MiddlePhalanxTW_TRAIN
│ ├── MoteStrain_TRAIN
│ ├── NonInvasiveFatalECG_Thorax1_TRAIN
│ ├── NonInvasiveFatalECG_Thorax2_TRAIN
│ ├── OSULeaf_TRAIN
│ ├── OliveOil_TRAIN
│ ├── PhalangesOutlinesCorrect_TRAIN
│ ├── Phoneme_TRAIN
│ ├── Plane_TRAIN
│ ├── ProximalPhalanxOutlineAgeGroup_TRAIN
│ ├── ProximalPhalanxOutlineCorrect_TRAIN
│ ├── ProximalPhalanxTW_TRAIN
│ ├── RefrigerationDevices_TRAIN
│ ├── ScreenType_TRAIN
│ ├── ShapeletSim_TRAIN
│ ├── ShapesAll_TRAIN
│ ├── SmallKitchenAppliances_TRAIN
│ ├── SonyAIBORobotSurfaceII_TRAIN
│ ├── SonyAIBORobotSurface_TRAIN
│ ├── StarLightCurves_TRAIN
│ ├── Strawberry_TRAIN
│ ├── SwedishLeaf_TRAIN
│ ├── Symbols_TRAIN
│ ├── ToeSegmentation1_TRAIN
│ ├── ToeSegmentation2_TRAIN
│ ├── Trace_TRAIN
│ ├── TwoLeadECG_TRAIN
│ ├── Two_Patterns_TRAIN
│ ├── UWaveGestureLibraryAll_TRAIN
│ ├── Wine_TRAIN
│ ├── WordsSynonyms_TRAIN
│ ├── WormsTwoClass_TRAIN
│ ├── Worms_TRAIN
│ ├── synthetic_control_TRAIN
│ ├── uWaveGestureLibrary_X_TRAIN
│ ├── uWaveGestureLibrary_Y_TRAIN
│ ├── uWaveGestureLibrary_Z_TRAIN
│ ├── wafer_TRAIN
│ └── yoga_TRAIN
├── debug
│ ├── __pycache__
│ │ └── dbd_cf.cpython-37.pyc
│ ├── cf.py
│ ├── dbd_cf.py
│ ├── dowmsample_ddtw_dbg.py
│ ├── downsample
│ │ ├── __pycache__
│ │ │ ├── utils.cpython-37.pyc
│ │ │ └── utils.cpython-38.pyc
│ │ └── utils.py
│ ├── downsample_dtw_dbg.py
│ ├── downsample_eventdtw_dbg.py
│ ├── downsample_shapedtw_dbg.py
│ ├── dtw.py
│ └── parameter_cal
│ │ ├── __pycache__
│ │ ├── cf.cpython-37.pyc
│ │ ├── cf.cpython-38.pyc
│ │ ├── utils.cpython-37.pyc
│ │ └── utils.cpython-38.pyc
│ │ ├── cf.py
│ │ ├── convex_detect.py
│ │ ├── eventdtw.py
│ │ ├── original_eventdtw_downsample.py
│ │ ├── parameter_cal_with_dDTW.py
│ │ ├── parameter_cal_with_dtw.py
│ │ └── utils.py
├── downsample
│ ├── __pycache__
│ │ └── utils.cpython-37.pyc
│ ├── downsample_with_dDTW.py
│ ├── downsample_with_dtw.py
│ ├── downsample_with_eventdtw.py
│ ├── downsample_with_shapedtw.py
│ └── utils.py
├── dtw.py
├── figure
│ └── Alignment.jpg
├── parameter_cal
│ ├── __pycache__
│ │ ├── cf.cpython-37.pyc
│ │ └── utils.cpython-37.pyc
│ ├── cf.py
│ ├── convex_detect.py
│ ├── eventdtw.py
│ ├── original_eventdtw_downsample.py
│ ├── parameter_cal_with_dDTW.py
│ ├── parameter_cal_with_dtw.py
│ └── utils.py
└── sdtw
│ ├── __pycache__
│ ├── config.cpython-37.pyc
│ └── utils.cpython-37.pyc
│ ├── config.py
│ ├── downsample_modi_shapedtw.py
│ ├── parameter_cal_with_shapedtw.py
│ ├── test.py
│ └── utils.py
├── hpc:group:dunnlab:yj167:tes.textClipping
├── json_table_convertor.ipynb
└── requirements.txt
/.idea/Pre-process.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Basis_Devices/Basis_Device_PreprocessingEDA.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Basis Device Preprocessing and EDA"
3 | author: "Peter Cho"
4 | date: "9/13/2019"
5 | output: pdf_document
6 | ---
7 |
8 | # Load the libraries
9 | ```{r setup, include=FALSE}
10 | knitr::opts_chunk$set(echo = TRUE)
11 | library(tidyverse)
12 | library(Hmisc)
13 | library(mltools)
14 | library(lsr)
15 | library(binr)
16 | library(reshape)
17 | library(RSQLite)
18 | library(ProjectTemplate)
19 | ```
20 |
21 | # Recreate supplementary figures from open access tidied data set
22 | ```{r setup, include=FALSE}
23 | og_clean_PLOS <- readxl::read_xlsx("C:/Users/chope/Downloads/stanford/wearables/Support_data_for_Figures/S4 Fig/FigS4AB.xlsx", col_names = FALSE)
24 | og_clean_PLOS <- t(og_clean_PLOS[,-c(1)])
25 | rownames(og_clean_PLOS) <- 1:nrow(og_clean_PLOS)
26 | melt_clean_PLOS = melt(og_clean_PLOS)
27 |
28 | ggplot(melt_clean_PLOS, aes(x = X1, y = value, color = as.factor(X2))) +
29 | geom_line() +
30 | xlab("Activity Ventile") +
31 | ylab("HR") +
32 | ggtitle("Tidied Data PLOS HR vs. Activity Ventile")
33 | # ggsave("og_PLOS_Figure_Linear.png")
34 |
35 | cor_melt_clean_PLOS <- melt_clean_PLOS %>%
36 | group_by(X2) %>%
37 | summarise(d = cor(1:19, value))
38 |
39 | ggplot(cor_melt_clean_PLOS) +
40 | geom_point(aes(x = X2, y = d))+
41 | xlab("Participant Number") +
42 | ylab("Correlation Coefficient HR~Activity Ventile") +
43 | ggtitle("Tidied Data PLOS Correlation Coefficient HR vs. Activity Ventile")
44 | # ggsave("og_PLOS_Figure_Points.png")
45 |
46 | ```
47 |
48 | # Generate supplementary figures from unprocessed watch data set
49 |
50 | ## Select watch data for one participant. Change path according to file location
51 | ```{r setup, include=FALSE}
52 | single_participant <- read.csv("C:/Users/chope/Downloads/stanford/wearables/Transfer Folder/Basis_003.csv")
53 | ```
54 |
55 | ### Exploratory Analysis and Segmenting
56 | ```{r setup, include=FALSE}
57 | colnames(single_participant)
58 | head(single_participant)
59 | portion <- trunc((nrow(single_participant))*0.001)
60 | sample_single_participant <- sample(levels(single_participant$time), portion)
61 | sample_single_participant <- sample(single_participant$hr, portion)
62 | sum(is.na(single_participant$hr))/nrow(single_participant) # simple summary statistics
63 | sum(is.na(single_participant$accel_magnitude))/nrow(single_participant) # simple summary statistics
64 | sum(is.na(single_participant$skin_temp))/nrow(single_participant) # simple summary statistics
65 | ```
66 |
67 | ### Preprocessing Stage
68 | ```{r setup, include=FALSE}
69 | cc_single_participant <- single_participant %>%
70 | select("hr", "accel_magnitude") %>%
71 | na.omit() %>%
72 | arrange(accel_magnitude) %>%
73 | mutate(count = row_number())
74 | rp_data <- tapply(cc_single_participant$hr, cut(cc_single_participant$count, 19), mean)
75 | rp_data
76 | ```
77 |
78 | ### Test code for the ventile calculation
79 | ```{r setup, include=FALSE}
80 | complete_clean_single_participant[, "reorder"] <- bin_data(complete_clean_single_participant$accel_magnitude, bins=20, binType = "quantile")
81 | complete_clean_single_participant$reorder <- as.numeric(cut2(complete_clean_single_participant$accel_magnitude, m = length(complete_clean_single_participant$accel_magnitude)/25, g = 40))
82 | complete_clean_single_participant$reorder <- quantileCut(complete_clean_single_participant$accel_magnitude, 20)
83 | complete_clean_single_participant$reorder <- bins.quantiles(complete_clean_single_participant$accel_magnitude, max.breaks = length(complete_clean_single_participant$accel_magnitude)/10, 20)
84 |
85 |
86 | sim_single_participant <- complete_clean_single_participant %>%
87 | group_by(reorder) %>%
88 | summarise(avg_hr = mean(hr), number_val = n())
89 | ```
90 |
91 | ## Select watch data for all participants and generate activity ventiles for each participant. Change path according to file location
92 | ```{r}
93 | files <- list.files(path="C:/Users/chope/Downloads/stanford/wearables/Transfer Folder", pattern="*.csv", full.names=TRUE, recursive=FALSE)
94 |
95 | activity_ventile <- function(single_participant_csv){
96 | single_participant <- read.csv(single_participant_csv)
97 | cc_single_participant <- single_participant %>%
98 | select("hr", "accel_magnitude") %>%
99 | na.omit() %>%
100 | arrange(accel_magnitude) %>%
101 | mutate(count = row_number())
102 | rp_data <- tapply(cc_single_participant$hr, cut(cc_single_participant$count, 19), mean)
103 | return(as.data.frame(rp_data))
104 | }
105 |
106 | lapply(files, activity_ventile) %>%
107 | bind_rows() -> combined_df
108 |
109 | raw_PLOS <- data.matrix(combined_df)
110 | raw_PLOS <- matrix(raw_PLOS, nrow = 43, ncol = 19, byrow=TRUE)
111 | raw_PLOS <- as.data.frame(t(raw_PLOS))
112 | ```
113 |
114 | ## Generate the graphs for the raw data
115 | ```{r}
116 | raw_PLOS <- raw_PLOS %>%
117 | mutate(id = 1:nrow(raw_PLOS))
118 | melt_raw_PLOS <- melt(raw_PLOS, id = "id")
119 |
120 | ggplot(melt_raw_PLOS, aes(x = id, y = value, color = as.factor(variable))) +
121 | geom_line() +
122 | xlab("Activity Ventile") +
123 | ylab("HR") +
124 | ggtitle("Raw PLOS HR vs. Activity Ventile")
125 | # ggsave("raw_PLOS_Figure_Linear.png")
126 |
127 | cor_melt_raw_PLOS <- melt_raw_PLOS %>%
128 | group_by(variable) %>%
129 | summarise(d = cor(1:19, value))
130 |
131 | ggplot(cor_melt_raw_PLOS) +
132 | geom_point(aes(x = 1:nrow(cor_melt_raw_PLOS), y = d))+
133 | xlab("Participant Number") +
134 | ylab("Correlation Coefficient HR~Activity Ventile") +
135 | ggtitle("Raw PLOS Correlation Coefficient HR vs. Activity Ventile")
136 | # ggsave("raw_PLOS_Figure_Points.png")
137 | ```
138 |
139 | ## Pre-processed PLOS data. Change file path with the preprocessed watch database. Still need to add EDA to this section.
140 | ```{r}
141 | filename <- "C:/Users/chope/Google Drive/Grad School/Digital Functional Capacity/wearables_clinical_deID.db"
142 | sqlite.driver <- dbDriver("SQLite")
143 | db <- dbConnect(sqlite.driver,
144 | dbname = filename)
145 |
146 | ## Some operations
147 | dbListTables(db)
148 | demo_tb <- dbReadTable(db,"demographics")
149 | result_tb <- dbReadTable(db,"lab_results")
150 | link_tb <- dbReadTable(db,"subject_wearable_links")
151 | vitals_tb <- dbReadTable(db,"vitals")
152 | data_tb <- dbReadTable(db,"wearable_data")
153 | dbDisconnect(sqlite.driver, dbname = filename)
154 | ```
155 |
156 |
157 |
--------------------------------------------------------------------------------
/Basis_Devices/README.md:
--------------------------------------------------------------------------------
1 | Preprocessing and exploratory data analysis (EDA) of basis device data from the "Digital Health: Tracking Physiomes and Activity Using Wearable Biosensors Reveals Useful Health-Related Information" paper. Data is available at: https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.2001402#sec014.
2 |
3 | Devices included Basis B1, Basis Peak, and Scanadu. Basis device data were made available by the authors, with four parameters: time in the format MM/DD/YYYY h:min:s -UTC, heart rate (hr) in beats per minute, acceleration magnitude (accel_magnitude), skin temperature (skin_temp) in degree Fahrenheit. Some participant's data was split into two files so they were merged together before inputting into the code. Additional parameters, such as steps, activity, and calories, were analyzed in this study. Other parameters, such as food logging, continuous glucose metrics, and galvanic skin response, were collected but were not analyzed in this study.
4 |
--------------------------------------------------------------------------------
/Empatica_E4/E4FileFormatter.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# E4FileFormatter\n",
8 | "The E4FileFormatter is for longitudinal studies with the wearable sensor the Empatica E4. It compiles all .csv of sensors of varying time lengths and merges all into a complete .csv for each sensor for the duration of the study.\n",
9 | "***\n",
10 | "\n",
11 | "##### **Input:** Unzipped files of raw .csv files downloaded from Empatica. (You only need to specify files)\n",
12 | "##### **Output:** Properly formatted .csv files compiled from all recordings with correct datatimestamps\n",
13 | "***\n",
14 | "\n",
15 | "##### Format of input: \n",
16 | "Configuration of folders/files: \n",
17 | " > Folder for each participant ->\n",
18 | " > Folder named Empatica ->\n",
19 | " > Downloaded all folders (originally zipped) containing csv files from Empatica session\n",
20 | " \n",
21 | "***\n",
22 | "\n",
23 | "**Check:** \n",
24 | "* Time Zone Correction- may need to change this dependent on time zone the data from the watch was uploaded via the E4 Portal\n",
25 | "\n",
26 | "**Sources:**\n",
27 | "* Empatica Timestamp Explanation: https://support.empatica.com/hc/en-us/articles/202800715-Session-start-time-format-and-synchronization-\n",
28 | "* GitHub with helpful ideas on E4 Data here: https://github.com/Ev4ngelos/EmpaticaBiophysicalSync/blob/master/E4BioSync.py"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "***\n",
36 | "***\n",
37 | "### First, you need to Unzip files: \n",
38 | "Using Bash/Terminal:\n",
39 | "* cd to directory then:\n",
40 | "* find -name '*.zip' -exec sh -c 'unzip -d \"${1%.*}\" \"$1\"' _ {} \\;"
41 | ]
42 | },
43 | {
44 | "cell_type": "raw",
45 | "metadata": {},
46 | "source": [
47 | "find -name '*.zip' -exec sh -c 'unzip -d \"${1%.*}\" \"$1\"' _ {} \\;"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "***"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "## User-defined Input:"
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": null,
67 | "metadata": {},
68 | "outputs": [],
69 | "source": [
70 | "theid = '00000' #This is the subject ID number (name of file)\n",
71 | "filesource = 'C:/Users/X/X/' #This is the source folder that contains all of your participant folders"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "***"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": null,
84 | "metadata": {},
85 | "outputs": [],
86 | "source": [
87 | "import csv\n",
88 | "import datetime\n",
89 | "import math\n",
90 | "import time\n",
91 | "import collections\n",
92 | "from collections import OrderedDict\n",
93 | "import os.path\n",
94 | "import pandas as pd\n",
95 | "import glob"
96 | ]
97 | },
98 | {
99 | "cell_type": "markdown",
100 | "metadata": {},
101 | "source": [
102 | "## Import & Format EDA, TEMP, HR, BVP\n",
103 | "Functions: \n",
104 | "* readFile() - reads file into dictionary and corrects for time zone\n",
105 | "* formatFile() - formats into dataframe with time as timestamp using datetime (ISO8601), formats sensor values to float, writes to .csv\n",
106 | "* importandexport() - finds all files of sensor type in participant folder and runs formatfile for each input file"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": null,
112 | "metadata": {},
113 | "outputs": [],
114 | "source": [
115 | "def readFile(file):\n",
116 | " dict = OrderedDict()\n",
117 | "\n",
118 | " with open(file, 'rt') as csvfile:\n",
119 | " reader = csv.reader(csvfile, delimiter='\\n')\n",
120 | " i =0;\n",
121 | " for row in reader:\n",
122 | " if(i==0):\n",
123 | " timestamp=row[0]\n",
124 | " #print(timestamp)\n",
125 | " timestamp=float(timestamp)-3600*4 #Time Zone Correction - will need to change depending on time zone!\n",
126 | " #print(timestamp)\n",
127 | " elif(i==1):\n",
128 | " hertz = float(row[0])\n",
129 | " elif(i==2):\n",
130 | " dict[timestamp]=row[0]\n",
131 | " else:\n",
132 | " timestamp = timestamp + 1.0/hertz\n",
133 | " dict[timestamp]=row[0]\n",
134 | " i = i+1.0\n",
135 | " return dict"
136 | ]
137 | },
138 | {
139 | "cell_type": "code",
140 | "execution_count": null,
141 | "metadata": {},
142 | "outputs": [],
143 | "source": [
144 | "def formatfile(file, idd, typed):\n",
145 | " EDA = {}\n",
146 | " EDA = readFile(file = file)\n",
147 | " EDA = {datetime.datetime.utcfromtimestamp(k).strftime('%Y-%m-%d %H:%M:%S.%f'): v for k, v in EDA.items()}\n",
148 | " EDAdf = pd.DataFrame.from_dict(EDA, orient='index', columns=['EDA'])\n",
149 | " EDAdf['EDA'] = EDAdf['EDA'].astype(float)\n",
150 | " \n",
151 | " EDAdf['Datetime'] =EDAdf.index\n",
152 | " EDAdf['Datetime'] = pd.to_datetime(EDAdf['Datetime'], format='%Y-%m-%dT%H:%M:%S.%f')\n",
153 | " EDAdf = EDAdf.set_index('Datetime')\n",
154 | " \n",
155 | " out_filename = (filesource + idd + '/' + typed + '.csv')\n",
156 | " EDAdf.to_csv(out_filename, mode='a', header=False)\n",
157 | " print('Done')"
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": null,
163 | "metadata": {},
164 | "outputs": [],
165 | "source": [
166 | "def importandexport(idd, typed):\n",
167 | " configfiles = glob.glob((filesource + idd + '/Empatica/*/' + typed + '.csv'))\n",
168 | " print(configfiles)\n",
169 | " \n",
170 | " [formatfile(file, idd, typed) for file in configfiles]\n",
171 | " print(('Completed Import and Export of:' + typed))"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": null,
177 | "metadata": {},
178 | "outputs": [],
179 | "source": [
180 | "listtyped = ['EDA','TEMP', 'HR','BVP'] \n",
181 | "[importandexport(theid, typed) for typed in listtyped]"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "metadata": {},
187 | "source": [
188 | "## Import & Format ACC\n",
189 | "Functions: \n",
190 | "* processAcceleration() - converts 3 axis to float values\n",
191 | "* readAccFile() - reads file into dictionary and corrects for time zone\n",
192 | "* formatAccFile() - formats into dataframe with time as timestamp using datetime (ISO8601), formats sensor values to float, writes to .csv\n",
193 | "* importandexport() - finds all files of sensor type 'ACC' in participant folder and runs formatfile for each input file"
194 | ]
195 | },
196 | {
197 | "cell_type": "code",
198 | "execution_count": null,
199 | "metadata": {},
200 | "outputs": [],
201 | "source": [
202 | "def processAcceleration(x,y,z):\n",
203 | " x = float(x)\n",
204 | " y = float(y)\n",
205 | " z = float(z) \n",
206 | " return {'x':x,'y':y,'z':z}"
207 | ]
208 | },
209 | {
210 | "cell_type": "code",
211 | "execution_count": null,
212 | "metadata": {},
213 | "outputs": [],
214 | "source": [
215 | "def readAccFile(file):\n",
216 | " dict = OrderedDict()\n",
217 | " \n",
218 | " with open(file, 'rt') as csvfile:\n",
219 | " reader = csv.reader(csvfile, delimiter=',')\n",
220 | " i=0;\n",
221 | " for row in reader:\n",
222 | " if(i == 0):\n",
223 | " timestamp = float(row[0])-3600*4 #Time Zone Correction\n",
224 | " elif(i == 1): \n",
225 | " hertz=float(row[0])\n",
226 | " elif(i == 2):\n",
227 | " dict[timestamp]= processAcceleration(row[0],row[1],row[2])\n",
228 | " else:\n",
229 | " timestamp = timestamp + 1.0/hertz \n",
230 | " dict[timestamp] = processAcceleration(row[0],row[1],row[2])\n",
231 | " i = i + 1\n",
232 | " return dict"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": null,
238 | "metadata": {},
239 | "outputs": [],
240 | "source": [
241 | "def formatAccfile(file, idd, typed):\n",
242 | " EDA = {}\n",
243 | " EDA = readAccFile(file = file)\n",
244 | " EDA = {datetime.datetime.utcfromtimestamp(k).strftime('%Y-%m-%d %H:%M:%S.%f'): v for k, v in EDA.items()}\n",
245 | " EDAdf = pd.DataFrame.from_dict(EDA, orient='index', columns=['x', 'y', 'z'])\n",
246 | " \n",
247 | " EDAdf['x'] = EDAdf['x'].astype(float)\n",
248 | " EDAdf['y'] = EDAdf['y'].astype(float)\n",
249 | " EDAdf['z'] = EDAdf['z'].astype(float)\n",
250 | " \n",
251 | " EDAdf['Datetime'] =EDAdf.index\n",
252 | " EDAdf['Datetime'] = pd.to_datetime(EDAdf['Datetime'], format='%Y-%m-%dT%H:%M:%S.%f')\n",
253 | " EDAdf = EDAdf.set_index('Datetime')\n",
254 | " \n",
255 | " out_filename = (filesource + idd + '/' + typed + '.csv')\n",
256 | " EDAdf.to_csv(out_filename, mode='a', header=False)\n",
257 | " print('Done')"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": null,
263 | "metadata": {},
264 | "outputs": [],
265 | "source": [
266 | "def importandexportAcc(idd, typed):\n",
267 | " configfiles = glob.glob((filesource + idd + '/Empatica/*/' + typed + '.csv'))\n",
268 | " print(configfiles)\n",
269 | " \n",
270 | " [formatAccfile(file, idd, typed) for file in configfiles]\n",
271 | " print(('Completed Import and Export of:' + typed))"
272 | ]
273 | },
274 | {
275 | "cell_type": "code",
276 | "execution_count": null,
277 | "metadata": {},
278 | "outputs": [],
279 | "source": [
280 | "importandexportAcc(theid, 'ACC') "
281 | ]
282 | },
283 | {
284 | "cell_type": "markdown",
285 | "metadata": {},
286 | "source": [
287 | "## Import & Format IBI\n",
288 | "Functions: \n",
289 | "* importIBI() - reads file into dataframe and corrects for time zone, formats time as timestamp using datetime (ISO8601), formats sensor values to float, writes to .csv\n",
290 | "* importandexportIBI() - finds all files of sensor type 'IBI' in participant folder and runs importIBI() for each input file"
291 | ]
292 | },
293 | {
294 | "cell_type": "code",
295 | "execution_count": null,
296 | "metadata": {},
297 | "outputs": [],
298 | "source": [
299 | "def importIBI(file, idd, typed):\n",
300 | " IBI = pd.read_csv(file, header=None)\n",
301 | " timestampstart = float(IBI[0][0])-3600*4\n",
302 | " IBI[0] = (IBI[0][1:len(IBI)]).astype(float)+timestampstart\n",
303 | " IBI = IBI.drop([0])\n",
304 | " IBI[0] = IBI[0].apply(lambda x: datetime.datetime.utcfromtimestamp(x).strftime('%Y-%m-%d %H:%M:%S.%f'))\n",
305 | " IBI = IBI.set_index(0)\n",
306 | " \n",
307 | " out_filename = (filesource + idd + '/' + typed + '.csv')\n",
308 | " IBI.to_csv(out_filename, mode='a', header=False)\n",
309 | " print('Done')"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": null,
315 | "metadata": {},
316 | "outputs": [],
317 | "source": [
318 | "def importandexportIBI(idd, typed):\n",
319 | " configfiles = glob.glob((filesource + idd + '/Empatica/*/' + typed + '.csv'))\n",
320 | " print(configfiles)\n",
321 | " \n",
322 | " [importIBI(file, idd, typed) for file in configfiles]\n",
323 | " print(('Completed Import and Export of:' + typed))"
324 | ]
325 | },
326 | {
327 | "cell_type": "code",
328 | "execution_count": null,
329 | "metadata": {},
330 | "outputs": [],
331 | "source": [
332 | "importandexportIBI(theid, 'IBI') "
333 | ]
334 | }
335 | ],
336 | "metadata": {
337 | "kernelspec": {
338 | "display_name": "Python 3",
339 | "language": "python",
340 | "name": "python3"
341 | },
342 | "language_info": {
343 | "codemirror_mode": {
344 | "name": "ipython",
345 | "version": 3
346 | },
347 | "file_extension": ".py",
348 | "mimetype": "text/x-python",
349 | "name": "python",
350 | "nbconvert_exporter": "python",
351 | "pygments_lexer": "ipython3",
352 | "version": "3.6.9"
353 | }
354 | },
355 | "nbformat": 4,
356 | "nbformat_minor": 4
357 | }
358 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pre-processing pipeline
2 |
3 | The pre-processing pipeline generates a processed .CSV file for data from wearable devices.
4 |
5 | Currently, the pipeline is capable of pre-processing raw data from the following devices/formats:
6 | 1. Time series data from ibeat [(Dynamic Time Warping algorithm to align Biomedical Signals of Non Uniform Sampling)](https://github.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/tree/master/Signal-Alignment)
7 | 2. Apple Watch
8 | 3. Fitbit Watch
9 | 4. Garmin Watch
10 | 5. Miband
11 | 6. ECG data stored as a EDF file
12 | 7. Biovotion
13 | 8. Empatica
14 | 9. Data stored as a JSON file
15 |
16 | ### Collaborator Repositories:
17 | * FLIRT: a repository that assists with preprcessing data, see repository
18 | for instructions:
19 | https://github.com/DigitalBiomarkerDiscoveryPipeline/flirt
20 |
21 | * FLIRT functions include:
22 | * zip_file_path : Receive the path of the zip file containing the data to process
23 | * flirt.with_.empatica: reads and transforms the Empatica .zip file into features directly.
24 | Calculates features for each time window (parameter window_length), and shifts each window
25 | by the step size (parameter window_step_size)
26 | * flirt.reader.empatica.read_acc_file_into_df : reads the ACC sensor modality into a DataFrame
27 | * flirt.reader.empatica.read_ibi_file_into_df : reads the IBI sensor modality into a DataFrame
28 | * flirt.reader.empatica.read_eda_file_into_df : reads the EDA sensor modality into a DataFrame
29 | * flirt.reader.empatica.read_bvp_file_into_df : reads the BVP sensor modality into a DataFrame
30 | * flirt.reader.empatica.read_hr_file_into_df : reads the HR sensor modality into a DataFrame
31 | * flirt.reader.empatica.read_temp_file_into_df : reads a temporary file sensor modality into a DataFrame
32 | * flirt.get_hrv_features: reads and processes data to get HRV features from HRV DataFrame
33 | * flirt.get_acc_features: reads and processes data to get ACC features from ACC DataFrame
34 | * flirt.get_eda_features : reads and processes data to get EDA features from EDA DataFrame
35 |
36 | * devicely: a python package for reading, de-identifying and writing data from
37 | various health monitoring sensors. Designed to make reading, accessing, and
38 | sharing sensor data more convenient while maintaining privacy. See
39 | repository for instructions:
40 | https://github.com/hpi-dhc/devicely
41 |
42 | * devicely getting started can be found here:
43 | https://hpi-dhc.github.io/devicely/examples.html#
44 | * devicely can access and manipulate data for the following devices:
45 | * Empatica E4
46 | * Spacelabs Blood Pressure Monitor
47 | * Bittium Faros
48 | * Biovotion Everion
49 | * Shimmer
50 | * Muse
51 |
52 |
53 | ### Steps to use the pipeline
54 |
55 | #### Aligning Biomedical Signals
56 |
57 | #### If you want to align biomedical signals of non-uniform sampling, please look into the ['Signal_Alignment'](https://github.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/tree/master/Signal-Alignment) folder and follow the steps.
58 |
59 |
60 | #### Data from watches
61 |
62 | The pipeline requires the pandas, numpy, pytz, datetime, os, sys, json, rowingdata, mne, and re packages.
63 |
64 | ```
65 | $ git clone https://github.com/DigitalBiomarkerDiscoveryPipeline/Pre-process.git
66 | In your local machine go to :
67 | $ cd /Pre-process/pipeline
68 | Run `Complete - Browse file` file or 'Complete - User path`
69 |
70 | ```
71 | #### If using the `Complete - Browse file` version of the code
72 | 1. The pipeline provides an option to browse the raw file in case of `Apple`, `Fitbit`, `Garmin`, `miband` and `ECG`. Please make sure to use these keywords when prompted to enter the `Type of watch`.
73 |
74 | 2. For `biovotion` and `empatica`, please provide the path to the folder where all the raw files are stored.
75 |
76 | 3. In case of `biovotion`, you will be prompted to enter the Device ID, you can find the same in the file name right after the vital sign name.
77 | For instance : If the filename is bop_1566404978515_BHR_5cda2e5e70116a01001eb098_1563897600_1563903059.csv, the Device ID is 5cda2e5e70116a01001eb098
78 |
79 | 4. The processed .csv file will be stored in the current working directory.
80 |
81 | #### If using the `Complete - User path` version of the code
82 | 1. Please provide the path to the file / folder for the watch selected.
83 |
84 | 2. For `biovotion` and `empatica`, please provide the path to the folder where all the raw files are stored.
85 |
86 | 3. In case of `biovotion`, you will be prompted to enter the Device ID, you can find the same in the file name right after the vital sign name.
87 | For instance : If the filename is bop_1566404978515_BHR_5cda2e5e70116a01001eb098_1563897600_1563903059.csv, the Device ID is 5cda2e5e70116a01001eb098
88 |
89 | 4. The processed .csv file will be stored in the current working directory.
90 |
91 | #### If you prefer using the terminal to run the code, please follow the following steps after you clone the repository:
92 |
93 | ```
94 | jupyter nbconvert --to python Complete\ -\ Browse\ file.ipynb
95 | ```
96 | or
97 | ```
98 | jupyter nbconvert --to python Complete\ -\ User\ path.ipynb
99 | ```
100 |
101 | Then run the file from terminal using:
102 | ```
103 | python Complete\ -\ Browse\ file.py or python Complete\ -\ User\ path.py
104 | ```
105 | #### Data stored as a JSON file
106 |
107 | #### If you want to convert a JSON file to a dataframe, please look into the [json_table_convertor.ipynb](./json_table_convertor.ipynb)
108 |
109 | 1. In this notebook, two situations are discussed based on the sample data provided by the Open_mHealth: https://www.openmhealth.org/documentation/#/schema-docs/schema-library.
110 |
111 | 2. The convertor code may need to be adjusted based on the structure of the actual data.
112 |
113 | ### Functions
114 |
115 | The pipeline currently uses the following functions.
116 |
117 | | Plugin | README |
118 | | ------ | ------ |
119 | | preprocessed_output | main function that calls respective functions based on choice of watch|
120 | | readcsv | calls pandas read_csv function with or without header |
121 | | apple | function to process raw data from apple watch |
122 | | fitbit | function to process raw data from fitbit watch |
123 | | garmin | function to process raw data from garmin watch |
124 | | miband | function to process raw data from miband watch |
125 | | ecg | function to process raw ecg data stored as a .EDF file |
126 | | biovotion | function to process raw data from biovotion watch |
127 | | empatica | function to process raw data from empatica watch |
128 | | process_df | Modifies column names and adds watch types |
129 | | output | Stores output file with watch name |
130 | | get_filenames | Used by biovotion and empatica to obtain all .csv files in a folder |
131 | | preprocess_empatica | Pre-processing function for empatica, used to obtain values of vitals and frequency rate |
132 | | add_time_empatica | Add time function for empatica, used to add time for each vital sign |
133 | | import_json | Receive the path of json files and create a dataframe |
134 | | [FLIRT](https://github.com/DigitalBiomarkerDiscoveryPipeline/flirt) | a repository that assists with preprcessing data for: Empatica E4 or Holter ECGs |
135 | | [devicely](https://github.com/hpi-dhc/devicely) | a python package for reading, de-identifying and writing data from
136 | various health monitoring sensors |
137 |
138 |
139 | ##### apple functions:
140 | main : calls all other functions to process raw data
141 | dict_df : Creates a data dictionary with information like Workout_date, Duration, Calories burnt, Mean heart rate, Maximum heart rate, and Notes
142 | pre_process_apple : Creates a header for the apple dataframe
143 | add_time : Calculates actual time using start time and elapsed time information
144 | rename_cols : Renames column names of the dataframe
145 | output_dict : Outputs apple watch processed data as .csv and data dictionary as a .json file
146 | ##### fitbit functions:
147 | main : calls all other functions to process raw data
148 | add_time : Calculates elapsed time using actual time information
149 | rename_cols : Renames column names of the dataframe
150 | ##### garmin functions:
151 | main : calls all other functions to process raw data
152 | add_time : Obtains actual time by converting timestamp to UTC. Also calculates elapsed time using actual time information
153 | rename_cols : Renames column names of the dataframe
154 |
155 | ##### miband functions:
156 | main : calls all other functions to process raw data
157 | add_time : Calculates elapsed time using actual time information
158 | rename_cols : Renames column names of the dataframe
159 |
160 | ##### ecg functions:
161 | get_data : Processes .EDF file to obtain raw data in a .CSV file. It stores raw data as a .CSV file in the current working directory.
162 | main : calls all other functions to process raw data
163 | pre_process_ECG : Drop unnecessary data columns from raw data .CSV file
164 | add_time : Calculates elapsed and actual time using start time and sampling rate information
165 | rename_cols : Renames column names of the dataframe
166 |
167 | ##### biovotion functions:
168 | main : calls all other functions to process raw data
169 | extract_names : Extracts names of the vital signs being measured by the watch using .CSV filenames
170 | read_data : Reads all CSV files in the folder containing vital sign measurements. Processes column names.
171 | create_df_final : Creates one single dataframe
172 | add_time : Calculates actual time by converting timestamp to UTC time. Also calculates elapsed time.
173 |
174 | ##### empatica functions:
175 | read_data : Reads all .CSV files data stored in the folder and processes each file. It calculates time using sampling frequency and start time for each file.
176 | all_dfs : All dataframes are combined to create one single dataframe
177 | main : calls all other functions to process raw data
178 |
179 | #### JSON to dataframe convertor functions:
180 | initial_sole_json : Receive the path of the first json file and use this json file to initialize the dataframe.
181 | import_new_sole_json : Receive the path of the following json file and append the new json file to the dataframe.
182 | import_mul_json : Receive the path of the json file with information of all patient.
183 |
184 | ### Continued Development
185 |
186 | We are frequently updating this package with new devices and insights from the DBDP (Digital Biomarker Discovery Pipeline).
187 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/Signal-Alignment.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/other.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Signal-Alignment/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Signal-Alignment/README.md:
--------------------------------------------------------------------------------
1 | # ibeat-edtw
2 | ## About the data source
3 | 84 public data sets in the ***data*** folder could be downloaded from http://www.cs.ucr.edu/~eamonn/time_series_data/
4 |
5 | ## Supoorted Dynamic Time Warping Methods
6 | The comparison of the following four DTW methods based on Singularity Score and Error Rate could be obtained by running programs in ***downsample*** folder
7 | * Dynamic Time Warping
8 | * Derivative Dynamic Time Warping
9 | * shapeDTW
10 | * EventDTW
11 |
12 | Table 1 in supplementary materials and Table 1 in article are available by running
13 |
14 | ```
15 | downsample_with_dDTW.py
16 | downsample_with_dtw.py
17 | downsample_with_eventdtw.py
18 | downsample_with_shapedtw.py
19 | ```
20 |
21 | ## Signal Alignment Visualization tool
22 |
23 | The alignment visualization could be realized by running programs in ***debug*** folder. Figure 2(a) middle and Figure 4 are available by running
24 |
25 | ```
26 | downsample_ddtw_dbg.py
27 | downsample_dtw_dbg.py
28 | downsample_eventdtw_dbg.py
29 | downsample_shapedtw_dbg.py
30 | ```
31 |
32 | Edit dbd_cf.py to set the name of data set and the number of signals
33 | ```
34 | debug_file = 'data/Beef_TRAIN'
35 | debug_line = 1
36 | ```
37 |
38 | ***
39 | Please note that this project works in Pycharm 2019.2.2
40 |
41 | Our paper ***EventDTW: An Improved Dynamic Time Warping Algorithm for Aligning Biomedical Signals of Nonuniform Sampling Frequencies*** has been published in Sensors and is avaliable online: https://www.mdpi.com/1424-8220/20/9/2700
42 |
--------------------------------------------------------------------------------
/Signal-Alignment/__pycache__/dtw.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/__pycache__/dtw.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/csv/19-005AW.csv:
--------------------------------------------------------------------------------
1 | ,t,q
2 | 0,0.0,-0.9152383796327851
3 | 1,3.0,-0.9153946410313557
4 | 2,10.0,-0.9145974163582694
5 | 3,13.0,-0.9113491319250685
6 | 4,20.0,-0.9049580439548421
7 | 5,22.0,-0.8965796030727549
8 | 6,29.0,-0.8893776541935783
9 | 7,35.0,-0.8875482013058553
10 | 8,40.0,-0.8945029997655589
11 | 9,43.0,-0.9111904643112088
12 | 10,46.0,-0.9354193336933397
13 | 11,55.0,-0.9623934230816674
14 | 12,60.0,-0.9860461446224731
15 | 13,65.0,-1.0006240247715437
16 | 14,66.0,-1.0020117606047962
17 | 15,75.0,-0.9883998544432446
18 | 16,79.0,-0.9603383741030045
19 | 17,81.0,-0.920125978968077
20 | 18,88.0,-0.8709957688590915
21 | 19,92.0,-0.8164347704709305
22 | 20,99.0,-0.7599701394707851
23 | 21,101.0,-0.7053522751163177
24 | 22,110.0,-0.6566985850422961
25 | 23,114.0,-0.618135232715247
26 | 24,118.0,-0.5929766011325022
27 | 25,121.0,-0.5828391543014206
28 | 26,130.0,-0.5871765897570552
29 | 27,134.0,-0.6034440369551577
30 | 28,139.0,-0.627830506986871
31 | 29,141.0,-0.6561894818353993
32 | 30,150.0,-0.6848722020763832
33 | 31,152.0,-0.7111487396156642
34 | 32,160.0,-0.7330815772059361
35 | 33,161.0,-0.7491646283534008
36 | 34,166.0,-0.7580522820444742
37 | 35,175.0,-0.7588314247172782
38 | 36,176.0,-0.7516454202152523
39 | 37,184.0,-0.7381828166672619
40 | 38,190.0,-0.7216141395187421
41 | 39,192.0,-0.7060489002990433
42 | 40,200.0,-0.6959639469339015
43 | 41,201.0,-0.695712085785123
44 | 42,210.0,-0.7090725361639973
45 | 43,211.0,-0.7383972789963121
46 | 44,217.0,-0.7835237227408337
47 | 45,225.0,-0.8410783523539705
48 | 46,228.0,-0.9048092448869067
49 | 47,232.0,-0.967039105044974
50 | 48,237.0,-1.0206181500909666
51 | 49,244.0,-1.0605336988386111
52 | 50,249.0,-1.084578966465509
53 | 51,252.0,-1.0930789390292406
54 | 52,258.0,-1.0880656036883545
55 | 53,262.0,-1.07231671800336
56 | 54,280.5,-1.0487227692583028
57 | 55,285.5,-1.0200094062060465
58 | 56,286.5,-0.9887929817250698
59 | 57,295.5,-0.9577290859365659
60 | 58,296.5,-0.9295248272924812
61 | 59,304.5,-0.9065283047094044
62 | 60,309.5,-0.8898454898800883
63 | 61,315.5,-0.8782738833178452
64 | 62,316.5,-0.8675115211189318
65 | 63,321.5,-0.8504150053702788
66 | 64,330.5,-0.8189766910506259
67 | 65,335.5,-0.7677858191865463
68 | 66,336.5,-0.697724727756286
69 | 67,341.5,-0.6174971307996929
70 | 68,346.5,-0.5412656046379283
71 | 69,352.5,-0.4826175481699436
72 | 70,357.5,-0.44762965122954707
73 | 71,365.5,-0.4309210906187335
74 | 72,370.5,-0.41701271333505824
75 | 73,373.5,-0.3862140281637763
76 | 74,376.5,-0.32183974911766794
77 | 75,381.5,-0.2155567531799603
78 | 76,387.5,-0.06926073463612269
79 | 77,395.5,0.10637147808587374
80 | 78,399.5,0.2955748720637301
81 | 79,405.5,0.48224047910349493
82 | 80,410.5,0.6542590266013742
83 | 81,413.5,0.805990878005582
84 | 82,416.5,0.9379430608863237
85 | 83,421.5,1.0541132692426982
86 | 84,428.5,1.1585489062973604
87 | 85,432.5,1.253187853449566
88 | 86,437.5,1.3377245542050906
89 | 87,441.5,1.4109389930423126
90 | 88,450.5,1.47214755537447
91 | 89,451.5,1.5217204466855354
92 | 90,460.5,1.5605991584099894
93 | 91,461.5,1.5896568238289146
94 | 92,470.5,1.6095165639087896
95 | 93,471.5,1.6210117517114477
96 | 94,480.5,1.6257601818806455
97 | 95,484.5,1.6262071359931478
98 | 96,489.5,1.6250232568999932
99 | 97,491.5,1.6240879360997056
100 | 98,496.5,1.6236443977432344
101 | 99,504.5,1.6220456775493002
102 | 100,510.5,1.616345048359145
103 | 101,515.5,1.603597978724461
104 | 102,517.5,1.5823880083934274
105 | 103,525.5,1.55387415739898
106 | 104,526.5,1.521788665259688
107 | 105,535.5,1.491183375130703
108 | 106,537.5,1.4665470029110161
109 | 107,541.5,1.4502346062952476
110 | 108,549.5,1.4420076386941276
111 | 109,555.5,1.4398244853109998
112 | 110,556.5,1.4412337439688017
113 | 111,565.5,1.4445091631266154
114 | 112,568.5,1.4489450209906602
115 | 113,571.6999998092651,1.4543589002446582
116 | 114,580.6999998092651,1.4604108975118626
117 | 115,581.6999998092651,1.4662980135115795
118 | 116,589.6999998092651,1.4710468105584857
119 | 117,591.6999998092651,1.4740911408669854
120 | 118,598.6999998092651,1.475621037955751
121 | 119,604.6999998092651,1.4763533428071958
122 | 120,607.6999998092651,1.4769075762331665
123 | 121,614.6999998092651,1.47708732081342
124 | 122,618.6999998092651,1.4756351594916792
125 | 123,623.6999998092651,1.4706781018146204
126 | 124,626.6999998092651,1.4608214366268177
127 | 125,635.6999998092651,1.446288644866202
128 | 126,640.6999998092651,1.429439160375981
129 | 127,645.6999998092651,1.4140037465815722
130 | 128,648.6999998092651,1.4031163296959228
131 | 129,654.6999998092651,1.396790020704867
132 | 130,659.6999998092651,1.3900269395764164
133 | 131,661.6999998092651,1.3725510101829277
134 | 132,667.6999998092651,1.3306175192865577
135 | 133,672.6999998092651,1.2505847181928853
136 | 134,676.6999998092651,1.1231771231574554
137 | 135,685.6999998092651,0.9470818950561034
138 | 136,689.6999998092651,0.7304737728997903
139 | 137,695.6999998092651,0.4897400714033966
140 | 138,699.6999998092651,0.24561746890198552
141 | 139,705.6999998092651,0.018088465688578102
142 | 140,709.6999998092651,-0.1780908149752299
143 | 141,712.6999998092651,-0.335747987229096
144 | 142,720.6999998092651,-0.45514411545062944
145 | 143,723.6999998092651,-0.5419006506314168
146 | 144,727.6999998092651,-0.6041164365305344
147 | 145,733.6999998092651,-0.649674402166784
148 | 146,738.6999998092651,-0.6843726370760741
149 | 147,741.6999998092651,-0.7112160516173424
150 | 148,750.6999998092651,-0.7308019456419058
151 | 149,751.6999998092651,-0.7422495360447631
152 | 150,760.6999998092651,-0.7441717907665181
153 | 151,764.6999998092651,-0.7352693613431633
154 | 152,769.6999998092651,-0.7145805351681483
155 | 153,771.6999998092651,-0.6816999410910136
156 | 154,778.6999998092651,-0.6372199475535324
157 | 155,782.6999998092651,-0.5834126806680175
158 | 156,787.6999998092651,-0.5248982445952018
159 | 157,795.6999998092651,-0.46876592950146334
160 | 158,796.6999998092651,-0.42359412582534567
161 | 159,805.6999998092651,-0.3971660886406373
162 | 160,810.6999998092651,-0.393616702915665
163 | 161,811.6999998092651,-0.4114357424103119
164 | 162,820.6999998092651,-0.44370815868933405
165 | 163,823.6999998092651,-0.48064405829450274
166 | 164,830.6999998092651,-0.5130701423550492
167 | 165,833.6999998092651,-0.5351276386728128
168 | 166,837.6999998092651,-0.5451557242905388
169 | 167,845.6999998092651,-0.5449994264354802
170 | 168,850.6999998092651,-0.5385300900833452
171 | 169,855.6999998092651,-0.530068488861489
172 | 170,856.6999998092651,-0.5231417944193056
173 | 171,862.6999998092651,-0.5197303958582171
174 | 172,869.8999998569489,-0.5201700263544122
175 | 173,871.8999998569489,-0.5235836988938141
176 | 174,880.8999998569489,-0.5286165027785428
177 | 175,885.8999998569489,-0.5339715231024571
178 | 176,886.8999998569489,-0.5386938309563618
179 | 177,891.8999998569489,-0.5421505842931994
180 | 178,896.8999998569489,-0.5439674555429593
181 |
--------------------------------------------------------------------------------
/Signal-Alignment/data/ItalyPowerDemand_TRAIN:
--------------------------------------------------------------------------------
1 | 1,-0.71052,-1.1833,-1.3724,-1.5931,-1.467,-1.3724,-1.0888,0.045967,0.92853,1.0861,1.2753,0.96005,0.61333,0.014447,-0.64748,-0.26923,-0.20619,0.61333,1.3698,1.4644,1.0546,0.58181,0.17205,-0.26923
2 | 1,-0.99301,-1.4268,-1.5799,-1.6054,-1.6309,-1.3758,-1.0185,-0.3551,0.71658,1.2014,1.1248,1.0483,0.79313,0.46142,0.48694,0.56348,0.61452,0.30832,0.25729,1.0993,1.0483,0.69107,-0.048906,-0.38062
3 | 2,1.3191,0.56977,0.19513,-0.085856,-0.17952,-0.27318,-0.085856,-1.3971,-1.1161,-0.74149,0.0078051,-0.085856,0.0078051,-0.4605,-0.55416,-0.74149,-0.74149,-0.74149,-1.1161,-0.4605,0.47611,2.3493,2.2557,1.6001
4 | 2,-0.81244,-1.1576,-1.4164,-1.5314,-1.5027,-1.4164,-1.6465,-0.46734,0.65427,1.0569,1.3445,1.2007,0.99938,0.65427,0.74055,0.88434,0.88434,0.68303,0.62551,0.4242,-0.0071898,-0.035949,0.10785,-0.26602
5 | 1,-0.97284,-1.3905,-1.5367,-1.6202,-1.6202,-1.4532,-0.99372,0.050469,0.63522,1.032,0.80229,0.82317,0.6561,0.38461,0.32196,0.48903,0.61433,1.3035,1.2409,1.0738,0.55168,0.42638,-0.17925,-0.6387
6 | 1,0.36742,-0.27781,-0.76173,-0.86927,-1.1381,-1.0843,-1.1381,-0.60042,-1.0843,-0.27781,0.36742,0.47496,0.52873,0.098577,-0.27781,-0.38535,-0.60042,-0.54665,-0.49289,0.36742,2.3031,2.088,1.7654,1.174
7 | 2,0.087213,-0.57646,-1.087,-1.3933,-1.3933,-1.2912,-1.7506,-0.72961,0.34247,1.7209,1.823,1.7719,1.1593,0.80193,0.18932,-0.01489,-0.065941,-0.065941,-0.01489,0.087213,-0.3212,-0.2191,0.75088,0.18932
8 | 1,-1.0991,-1.3756,-1.523,-1.5599,-1.5968,-1.4309,-1.1359,-0.23272,0.65207,0.947,1.0023,0.91013,0.79953,0.43087,0.5599,0.63363,0.8364,0.7811,1.2051,0.98386,0.59677,0.30184,-0.12212,-0.56451
9 | 1,-1.1499,-1.5492,-1.4893,-1.5692,-1.5692,-1.4494,-1.09,0.088196,0.34779,1.0667,1.1066,1.0467,0.64732,0.50754,0.60738,0.62735,0.68726,0.7272,1.0667,0.96682,0.58742,0.36776,-0.071555,-0.51087
10 | 2,-0.75624,-1.1884,-1.3155,-1.4426,-1.4426,-1.2901,-1.5443,-0.88334,0.41307,1.2011,1.2773,1.2519,0.99773,0.84521,0.89605,0.97231,1.0231,0.71811,0.31139,0.48933,-0.14616,-0.197,0.057195,-0.24784
11 | 2,-0.50952,-1.2396,-1.2396,-1.6046,-1.6046,-1.1483,-0.78329,-1.2396,-0.14449,0.95059,1.3156,1.4981,1.2244,0.85933,0.49431,0.76808,0.49431,0.49431,0.12928,-0.327,-0.69203,1.0418,0.85933,0.40305
12 | 1,-1.0048,-1.3816,-1.5575,-1.6077,-1.6579,-1.4319,-1.0802,0.22608,0.92946,1.1807,1.1053,0.87922,0.72849,0.52753,0.55265,0.65313,0.57777,0.27632,0.22608,1.2058,0.77873,0.52753,0.02512,-0.67825
13 | 1,-0.97487,-1.2824,-1.549,-1.6105,-1.631,-1.4875,-1.0159,-0.13414,0.68608,1.0347,1.0142,0.89113,0.52204,0.44001,0.399,0.41951,0.54254,1.3012,1.2192,0.91164,0.58355,0.52204,-0.19566,-0.60577
14 | 2,-0.87492,-1.2653,-1.4884,-1.6836,-1.6836,-1.5163,-1.2653,-0.3172,0.51937,1.1329,1.1886,1.1886,0.88189,0.57514,0.60303,0.63092,0.88189,0.49149,0.2684,0.35206,0.88189,0.63092,0.15686,-0.28931
15 | 1,-0.96432,-1.4333,-1.5271,-1.6209,-1.6678,-1.4333,-0.96432,-0.23742,0.65363,1.146,1.146,1.0054,0.77087,0.37225,0.37225,0.55984,0.53639,0.39569,0.46604,1.404,0.88812,0.55984,0.067415,-0.49535
16 | 2,0.83967,-0.36945,-0.42703,-0.83007,-0.94523,-0.88765,-1.8089,-1.521,-1.118,-0.42703,0.37905,0.66694,0.83967,0.14874,-0.081568,-0.31188,-0.54219,-0.2543,-0.023991,0.37905,0.95483,2.164,1.7033,1.473
17 | 1,-0.58552,-0.81972,-1.1878,-1.4554,-1.79,-1.3885,-1.0539,-0.41823,-0.45168,0.1171,0.5186,0.65243,0.55206,0.21748,-0.1171,-0.48514,0.016729,1.1543,1.422,1.6227,1.5223,1.3216,0.68589,-0.050187
18 | 1,-0.25806,-0.73144,-1.1259,-1.3626,-1.481,-1.4415,-1.0865,-0.77088,-0.81033,0.01808,0.33367,0.64925,0.6887,-0.10026,-0.21861,-0.29751,-0.25806,0.88594,1.5171,1.7144,1.6355,1.3593,0.84649,0.29422
19 | 2,-0.86958,-1.2261,-1.4181,-1.5278,-1.5278,-1.4729,-1.5552,-0.65019,0.50164,1.1873,1.2147,1.2969,1.0227,0.69361,0.69361,0.80331,0.80331,0.66619,0.39194,0.33709,0.090272,0.1177,0.44679,-0.019426
20 | 1,-1.0707,-1.314,-1.4824,-1.5573,-1.5573,-1.4824,-1.052,-0.17234,0.46399,0.9693,0.93187,0.91316,0.68857,0.63243,0.4827,0.52013,0.65114,1.2875,1.0816,1.0629,0.66986,0.31426,-0.26592,-0.71509
21 | 1,-1.042,-1.3488,-1.5214,-1.6173,-1.6365,-1.2146,-1.0995,-0.2557,0.77988,1.1442,1.1634,0.97165,0.85659,0.49222,0.45386,0.53057,0.70317,0.68399,1.1059,1.01,0.51139,0.24291,-0.21734,-0.69677
22 | 2,-0.81287,-1.1727,-1.5069,-1.5583,-1.6097,-1.3783,-1.1213,-0.63294,0.62652,1.3205,1.3976,1.3976,1.1663,0.75504,0.65222,0.70363,0.67793,0.42089,0.29238,0.086749,0.0096387,0.52371,0.18956,-0.42732
23 | 1,-1.0945,-1.3614,-1.6061,-1.6505,-1.6505,-1.4726,-1.1167,0.26227,0.84056,1.1297,1.1075,1.0185,0.77384,0.37348,0.37348,0.5959,0.55142,0.35124,0.50693,1.1742,0.7516,0.46245,0.017608,-0.33826
24 | 1,-0.83894,-1.1511,-1.4633,-1.5881,-1.713,-1.4321,-1.0262,-0.43313,0.22242,0.44093,0.97161,1.034,0.81553,0.44093,0.097551,0.097551,0.12877,1.034,1.3774,1.4711,1.0965,0.69066,0.066335,-0.33948
25 | 1,-0.96551,-1.345,-1.5584,-1.6533,-1.6296,-1.4636,-1.0604,0.078071,0.62358,1.264,1.1928,0.95562,0.7896,0.36268,0.41012,0.33896,0.50499,0.33896,0.52871,1.43,0.81332,0.50499,-0.0168,-0.44372
26 | 1,-0.40498,-1.0099,-1.3326,-1.4535,-1.4939,-1.2922,-0.8486,-0.52597,0.80491,1.4099,1.4099,1.2082,0.76458,0.11931,-0.32432,-0.24366,-0.163,-0.44531,-0.163,1.7325,1.4099,0.9259,0.15964,-0.24366
27 | 1,-0.92025,-1.3825,-1.5366,-1.6136,-1.6393,-1.4339,-0.99729,-0.3039,0.67199,1.1343,1.2113,1.2113,0.77472,0.36382,0.3895,0.33814,0.46654,0.3895,0.3895,1.3911,0.90313,0.62063,-0.098445,-0.32958
28 | 2,-0.64847,-1.0947,-1.3736,-1.4852,-1.6525,-1.4294,-0.81581,-0.87159,0.13248,1.0808,1.3597,1.3597,1.3039,0.85765,0.80187,0.91343,1.0808,0.57874,0.35561,-0.034864,-0.70425,0.18826,0.29983,-0.20221
29 | 2,-0.97386,-1.2951,-1.5629,-1.6432,-1.5093,-1.5093,-1.081,-0.38486,0.47187,1.3822,1.3286,1.2751,0.90024,0.65928,0.71283,0.71283,0.63251,0.36478,0.28446,0.12382,0.31123,0.84669,0.23092,-0.27777
30 | 1,-0.88822,-1.3608,-1.5847,-1.6096,-1.5847,-1.4603,-0.98772,-0.5151,0.50474,1.1017,1.1763,1.0271,0.67886,0.33062,0.45499,0.45499,0.57936,0.43012,0.45499,1.45,0.95248,0.75348,0.057004,-0.41561
31 | 1,-1.0434,-1.3483,-1.5008,-1.577,-1.6342,-1.4627,-1.0815,-0.2811,0.8433,0.97671,0.97671,0.86236,0.7099,0.38592,0.53838,0.51932,0.74802,1.0148,1.1673,1.0339,0.51932,0.30969,-0.10958,-0.56697
32 | 2,0.33926,-0.32542,-0.71315,-0.93471,-1.1009,-1.1009,-0.87932,-0.54698,-0.9901,-0.32542,0.28387,0.61621,0.50543,0.1177,-0.38081,-0.54698,-0.71315,-0.71315,-0.38081,0.45004,2.3887,2.0564,1.724,1.1701
33 | 2,-0.75213,-1.0693,-1.36,-1.4921,-1.5186,-1.3864,-1.4921,-0.59355,0.41075,1.1508,1.3093,1.2829,1.0715,0.86005,0.93933,0.9129,0.99219,0.7279,0.46361,0.27861,-0.17069,-0.19712,-0.11783,-0.24997
34 | 1,-0.35731,-0.85205,-1.3056,-1.4705,-1.5117,-1.4705,-1.017,-0.72836,-0.43977,0.013743,0.67339,0.75585,0.75585,0.17866,-0.39854,-0.27485,-0.027485,1.0857,1.5392,1.6629,1.5392,1.0857,0.59094,-0.027485
35 | 2,0.065389,-0.52988,-1.1251,-1.3957,-1.4498,-1.2875,-1.991,-0.74634,0.55243,1.4724,1.8512,1.743,1.2559,0.49831,-0.096956,0.17362,0.1195,0.065389,0.065389,0.28185,0.011274,-0.096956,0.55243,0.011274
36 | 2,-0.89604,-1.2313,-1.4117,-1.4891,-1.4891,-1.4375,-1.4891,-0.74133,0.47058,1.2184,1.1926,1.141,1.1152,0.75422,0.72844,0.85736,0.83158,0.9605,0.29009,0.36744,0.0064463,0.058017,0.2643,-0.07091
37 | 1,-1.1149,-1.3384,-1.5213,-1.6025,-1.6025,-1.501,-1.0337,-0.078731,0.49016,0.73397,0.69334,0.93715,0.97778,0.55111,0.55111,0.73397,0.81524,1.0997,1.0387,1.0794,0.61207,0.24635,-0.16,-0.60699
38 | 2,0.2081,-0.56485,-1.0405,-1.2783,-1.3378,-1.1,-1.8135,-0.74322,0.32702,1.6945,2.2297,1.8135,1.0405,0.2081,-0.029729,0.029729,0.029729,0.029729,-0.14864,0.029729,-0.2081,-0.26756,0.74322,0.14864
39 | 1,-1.1455,-1.3888,-1.6077,-1.6321,-1.5834,-1.3401,-0.9022,-0.48861,0.53321,1.1658,1.0928,0.97113,0.70351,0.46022,0.38724,0.58187,0.55754,0.38724,0.31425,1.3361,1.1171,0.70351,0.07096,-0.29398
40 | 2,-0.88008,-1.2583,-1.462,-1.5492,-1.6074,-1.5201,-1.0256,-0.7928,0.34185,0.77826,1.2438,1.2438,1.1565,0.66188,0.72007,0.80735,1.0692,0.86554,0.48732,0.42913,0.22548,0.51641,-0.094555,-0.3564
41 | 1,-0.41137,-0.67348,-1.1103,-1.2414,-1.4161,-1.3288,-0.84823,-0.58611,-0.80454,0.069169,0.68077,0.76814,0.63708,0.069169,-0.36769,-0.49874,-0.36769,-0.018202,1.7729,2.035,1.5545,1.4234,0.63708,0.025483
42 | 1,-0.98674,-1.3844,-1.5037,-1.5833,-1.623,-1.3446,-0.98674,-0.091963,0.92211,1.121,1.121,1.0016,0.80281,0.3256,0.34548,0.38525,0.52444,0.74316,1.2204,1.1408,0.54432,0.26595,-0.27092,-0.68848
43 | 2,-0.88996,-1.2677,-1.4421,-1.5293,-1.5293,-1.4712,-1.1806,-0.7156,0.24338,1.0571,1.2605,1.3186,1.0861,0.7374,0.82458,0.8827,0.96988,0.62116,0.4468,0.18526,0.098077,0.5921,0.098077,-0.39594
44 | 2,-0.026952,-0.6276,-1.1821,-1.5979,-1.4593,-1.2283,-1.7827,-1.2283,0.34268,1.3592,1.6826,1.544,0.89713,0.43509,0.065456,0.15786,-0.026952,0.15786,-0.026952,0.11166,0.15786,1.0819,0.89713,0.29648
45 | 1,-1.0644,-1.3238,-1.5615,-1.6047,-1.5831,-1.4318,-0.91312,-0.07024,0.64297,0.90232,0.90232,0.85909,0.66458,0.36201,0.36201,0.51329,0.59974,0.64297,1.3562,1.3778,0.83748,0.36201,-0.048628,-0.78345
46 | 2,-0.78046,-1.1359,-1.382,-1.4641,-1.4641,-1.382,-1.4914,-0.67108,0.23129,1.243,1.4618,1.4071,1.2977,0.69615,0.69615,0.83287,0.86021,0.45005,0.36801,0.25863,-0.014812,0.039877,0.20394,-0.26091
47 | 2,0.3222,-0.084789,-0.54992,-0.84062,-0.95691,-1.015,-0.72434,-1.4802,-1.1313,-0.37549,0.26406,0.49662,0.49662,0.14778,-0.25921,-0.25921,-0.6662,-0.43364,-0.49178,0.20592,2.1827,2.2409,1.7176,1.1943
48 | 2,-0.76022,-1.2362,-1.3948,-1.5799,-1.6857,-1.3948,-1.4742,-0.60157,0.58835,1.1172,1.3023,1.2494,0.9321,0.72056,0.747,0.82633,0.85277,0.61479,0.50902,0.40325,0.19171,0.085938,0.19171,-0.20493
49 | 2,0.50632,-0.34943,-0.86289,-1.2622,-1.3763,-1.2052,-0.86289,-1.6045,-0.97699,-0.064182,0.73452,0.79157,0.79157,0.16402,-0.34943,-0.23533,-0.23533,-0.29238,-0.064182,1.0198,1.0198,2.3319,1.4762,0.90567
50 | 1,-0.4688,-0.89854,-1.3673,-1.4455,-1.4845,-1.2501,-0.74227,-0.50787,0.50787,1.4455,1.4845,1.2111,0.8204,0.19533,-0.31253,-0.31253,-0.42973,-0.42973,-0.1172,1.7189,1.4845,0.9376,0.19533,-0.2344
51 | 1,-1.0668,-1.3888,-1.5498,-1.6418,-1.6188,-1.4348,-0.97474,-0.35367,0.63545,1.2335,1.0495,0.79647,0.58945,0.38242,0.47443,0.54344,0.54344,0.35942,0.45143,1.4175,1.0265,0.77347,0.083385,-0.33067
52 | 2,-0.19934,-0.70591,-1.2125,-1.5502,-1.5502,-1.4939,-1.0999,-0.93106,-0.25563,1.1515,1.7144,1.4892,1.1515,1.0952,0.082083,-0.19934,-0.030488,-0.030488,-0.086774,0.025798,0.47608,1.4892,0.53237,0.13837
53 | 2,-0.98161,-1.3422,-1.5345,-1.6547,-1.6066,-1.4384,-0.98161,-0.45274,0.74923,1.3021,1.3743,1.23,0.98963,0.77327,0.65307,0.41268,0.67711,0.4848,0.2444,0.19632,0.14824,0.74923,0.2444,-0.23639
54 | 2,0.29828,-0.51807,-1.0832,-1.3344,-1.2716,-1.2088,-1.9624,-0.76926,0.48667,1.617,1.9938,1.6798,1.2402,0.54947,-0.20409,-0.015699,0.10989,-0.078496,-0.015699,-0.015699,-0.015699,-0.26689,0.73786,0.047097
55 | 1,-0.4595,-0.9311,-1.439,-1.5115,-1.6204,-1.4027,-0.89482,0.012092,0.48369,1.318,1.3543,1.1004,0.51996,0.19348,-0.3144,-0.20557,-0.3144,-0.24184,0.3023,1.6808,1.6808,0.84645,0.12092,-0.27812
56 | 2,-0.95324,-1.6212,-1.3707,-1.4542,-1.4542,-1.5655,-1.1481,-0.25744,0.661,1.1898,1.2176,1.2455,0.99499,0.60534,0.661,0.71667,0.91149,0.52185,0.46618,0.27136,0.7445,0.29919,-0.17395,-0.50793
57 | 2,-0.82904,-1.1944,-1.5035,-1.644,-1.5878,-1.4754,-1.4473,-0.21077,0.68852,1.2787,1.2506,1.2506,0.99766,0.66042,0.63232,0.85714,0.77283,0.60422,0.29508,0.15457,0.12646,0.21077,0.32318,-0.21077
58 | 1,-1.119,-1.4021,-1.5437,-1.6043,-1.5437,-1.3819,-1.0583,-0.20897,0.45838,0.96394,1.0044,0.6606,0.72127,0.55949,0.59994,0.88305,0.80216,1.0651,1.1055,1.0044,0.57971,0.27637,-0.24941,-0.57297
59 | 1,-0.052621,-0.5752,-1.0978,-1.3591,-1.4462,-1.4026,-0.96713,-0.61875,-0.83649,-0.13972,0.55705,0.6006,0.55705,0.12157,-0.35746,-0.31391,-0.53165,-0.052621,1.4716,1.5587,1.907,1.5587,1.1232,0.29576
60 | 2,1.209,0.57029,-0.25093,-0.34217,-0.70715,-0.61591,-0.34217,-1.3459,-0.98089,-0.43342,0.11406,0.38779,0.29655,-0.15968,-0.43342,-0.70715,-0.52466,-0.88965,-0.70715,-0.43342,-0.25093,2.2127,2.2127,2.1215
61 | 2,-0.81595,-1.0806,-1.3452,-1.4334,-1.5216,-1.4334,-1.5216,-0.66894,0.15437,1.1835,1.3305,1.3011,1.2423,0.80125,0.80125,0.86006,0.91887,0.65423,0.47781,0.3602,-0.13967,-0.16907,0.15437,-0.11026
62 | 1,-1.2386,-1.3335,-1.5045,-1.5615,-1.5425,-1.4855,-1.0106,-0.13692,0.60385,1.0027,1.0027,0.90776,0.7558,0.52788,0.50888,0.64184,0.71782,1.0977,1.1357,0.92675,0.52788,0.29995,-0.26987,-0.57378
63 | 1,-1.0379,-1.3017,-1.4695,-1.5894,-1.6133,-1.5174,-1.0619,-0.0069928,1.2157,1.1438,1.1198,1.0959,0.97599,0.35264,0.42456,0.44854,0.44854,0.30469,0.44854,1.2157,0.66431,0.35264,-0.10289,-0.51047
64 | 2,-0.37358,-0.98663,-1.4464,-1.6763,-1.7529,-1.3698,-0.91,-0.98663,-0.22032,0.85253,1.0058,1.3123,1.2357,0.7759,0.46937,0.7759,0.92916,0.39274,0.16284,0.009579,-0.37358,1.3123,0.92916,-0.067053
65 | 1,-1.1592,-1.3014,-1.5249,-1.5656,-1.6062,-1.4436,-1.0779,0.019474,0.73071,1.1778,1.1778,1.0965,1.0355,0.79168,0.71039,0.48686,0.44622,0.48686,0.26333,0.89328,0.66975,0.46654,-0.12277,-0.65112
66 | 2,-0.69492,-1.2358,-1.4161,-1.5063,-1.5063,-1.5063,-1.0555,-1.0105,-0.063857,1.1081,1.3786,1.3335,1.1081,0.74751,0.61228,1.063,0.92781,0.61228,0.25167,0.16152,0.026294,0.65736,0.2066,-0.19908
67 | 2,0.98403,0.16966,-0.51942,-0.83264,-0.89529,-0.70736,-0.70736,-1.7723,-0.89529,0.48288,0.67081,0.73346,0.73346,0.42024,-0.51942,-0.64471,-0.70736,-0.77,-0.70736,-0.26885,0.2323,2.4248,1.9237,1.172
68 |
--------------------------------------------------------------------------------
/Signal-Alignment/data/MoteStrain_TRAIN:
--------------------------------------------------------------------------------
1 | 2,0.39815,0.50392,0.5259,0.6073,0.57289,0.8041,0.72174,0.6883,-0.41905,-0.85395,-0.92464,-0.59134,-0.45592,-0.058858,-0.011106,0.19553,0.27646,0.26734,0.34066,0.39272,0.41256,0.52252,0.7027,0.71322,0.79314,0.78638,0.84002,0.8289,0.86126,0.87135,0.869,0.90895,0.84508,0.8711,0.88145,0.84962,0.89054,0.78536,0.4988,0.40273,-0.49187,-0.12686,-0.077103,-0.19989,-0.70662,-0.93536,-0.905,-0.94536,-0.96573,-0.98095,-0.88404,-0.78652,-7.5177,-0.65079,-0.62848,-0.52885,-0.33368,-0.14234,-0.095347,-0.045828,-0.070611,-0.27178,0.068569,0.0027535,0.13207,0.27793,-0.03542,-0.26409,-0.28218,-0.18155,-0.18155,-0.19203,-0.18051,-0.14496,-0.10317,-0.10578,0.020968,0.10877,0.13079,0.17219,0.17392,0.21031,0.25998,0.28885
2 | 2,-1.0944,-1.2513,-1.4177,-1.5015,-1.3545,-1.1938,-1.0366,-0.80411,-0.76007,-0.48943,-0.3729,-0.24395,-0.14796,0.055676,0.1827,0.34624,0.48797,0.55566,0.58059,0.5533,0.58889,0.56041,0.55851,0.68723,0.70853,0.76408,0.74518,0.74754,0.75935,0.83961,0.83355,0.9156,0.9103,1.0196,1.0249,1.0232,1.0818,1.0964,1.1427,1.1427,1.1568,1.1755,1.1849,1.2164,1.2424,1.278,1.3127,1.3553,1.3611,1.3611,1.332,1.2899,1.0344,0.49049,0.0073731,-0.30927,-0.43549,-0.77474,-0.95858,-1.1072,-1.2005,-1.3415,-1.4649,-1.528,-1.5697,-1.6284,-1.5817,-1.5802,-1.4152,-1.3681,-1.2951,-1.2119,-1.1099,-1.0816,-0.83104,-0.71608,-0.63552,-0.43112,-0.25423,-0.092979,0.054245,0.17415,0.28896,0.36295
3 | 1,0.0817,0.05758,0.019309,-0.017998,-0.045013,-0.058199,-0.12284,-0.42194,-0.41229,-0.30451,-0.17494,-0.050343,0.10293,0.10872,0.25344,0.39546,0.58611,0.49443,0.61313,0.56315,0.59141,0.61139,0.53021,0.57431,0.41167,0.4374,0.23106,0.036675,-0.012852,0.16275,0.10872,0.048897,-0.058393,0.41785,0.64323,0.73276,0.73071,0.68825,0.67893,0.63088,0.57376,0.52668,0.494,0.45412,0.39237,0.34529,0.28946,0.25087,0.20649,0.14758,0.097964,-0.016712,-0.11628,-0.17301,-0.23283,-0.28558,-0.32353,-0.35247,-0.38849,-0.42117,-0.4779,-0.53,-0.55977,-0.59818,-0.60057,-0.6535,-0.74805,-0.096471,0.32098,0.39816,-8.4093,0.099067,0.10293,0.030565,-0.21354,-0.38592,0.025096,0.19298,0.22192,0.1805,0.16918,0.12222,0.053527,0.023811
4 | 1,-1.4255,-1.4517,-1.4868,-1.5353,-1.5586,-1.5829,-1.62,-1.6021,-1.5187,-1.3317,-1.067,-0.81964,-0.54595,-0.30171,-0.076982,0.16832,0.42748,0.64517,0.95513,1.1231,1.3216,1.4551,1.5155,1.6304,1.6821,1.8094,1.9846,1.8922,1.8169,1.7685,1.7251,1.6503,1.5158,1.3787,1.2184,1.0256,0.87072,0.67111,0.52028,0.38665,0.27756,0.20898,0.11567,0.050917,-0.014238,-0.068032,-0.1174,-0.15782,-0.1904,-0.21429,-0.23485,-0.25918,-0.29168,-0.32652,-0.36174,-0.39371,-0.41724,-0.45005,-0.4819,-0.51445,-0.55017,-0.57516,-0.60789,-0.63745,-0.67281,-0.69657,-0.72508,-0.75053,-0.77259,-0.80046,-0.84559,-0.85463,-0.85343,-0.88323,-0.89325,-0.90033,0.19081,0.70851,0.19209,0.060067,0.17972,0.38296,0.41692,0.49505
5 | 1,-0.50086,-0.52962,-0.56982,-0.62499,-0.67811,-0.71273,-0.74457,-0.76908,-0.7996,-0.82249,-0.8467,-0.86915,-0.88799,-0.907,-0.91052,-0.92402,-0.93106,-0.47235,0.21811,0.35633,0.54913,0.68219,0.8794,1.0624,1.2041,1.3039,1.4453,1.5974,1.7267,1.7781,1.8579,1.9494,1.9877,1.9705,1.9155,1.3129,0.99249,0.86584,0.73137,0.62602,0.49924,0.40915,0.25579,0.14651,0.063753,-0.017124,-0.14073,-0.18921,-0.21723,-0.26345,-0.31187,-0.3418,-0.34533,-0.37995,-0.40343,-4.0598,-0.4404,-0.4721,-0.49323,-0.52316,-0.54018,-0.55353,-0.61413,-0.64993,-0.64069,-0.65486,-0.67678,-0.69219,-0.70848,-0.72917,-0.75382,-0.76878,-0.77759,-0.78639,-0.78692,-0.79314,-0.79901,0.2005,0.51392,0.64245,0.91184,1.0879,1.1076,1.1736
6 | 2,-0.18521,-0.11495,0.11972,0.12774,0.2871,0.11832,-0.33943,-0.40273,-0.3796,-0.31763,-0.09183,-0.04318,0.021799,0.43516,0.54793,0.68072,0.83313,0.77627,0.86222,0.45886,0.76724,0.54272,0.54271,0.50219,0.50924,0.51911,0.56384,0.61661,0.61661,0.64096,0.63454,0.62048,0.61083,0.65702,0.68862,0.79307,0.80864,0.86024,0.88236,0.8975,0.94683,0.95241,0.99144,0.98587,0.97193,0.98819,1.036,1.0207,1.0381,1.0416,1.0926,1.1111,1.1419,1.1431,1.0644,0.9103,0.79023,0.12566,-0.35477,-0.47192,-0.77294,-1.1043,-1.2547,-1.4316,-1.6276,-1.7229,-1.8552,-1.8788,-1.9756,-1.9185,-1.9376,-1.8924,-1.7105,-1.7773,-1.755,-1.7328,-1.443,-1.1818,-1.0366,-0.97212,-0.85386,-0.63134,-0.44597,-0.2823
7 | 2,-0.02683,-0.058356,-0.051583,-0.15076,-0.11128,-0.1547,-0.020105,-0.068467,-0.19872,-0.40082,-0.44647,-0.5016,-0.47833,0.67005,0.84461,0.98198,1.0531,0.94031,0.9698,0.95371,0.96293,0.99332,1.0055,1.0248,0.99849,1.0207,1.0292,1.0889,1.0957,1.0951,1.0889,1.0763,1.091,1.1091,1.1463,1.1777,1.2293,1.2567,1.2483,1.3061,1.3145,1.3712,1.4012,1.4068,1.4289,1.4215,1.4305,-0.038077,-0.24561,-0.47508,-0.73061,-0.61928,-0.91713,-1.0094,-1.0896,-0.62781,-0.56453,-0.67518,-0.91504,-1.0643,-1.1976,-1.2834,-1.2997,-1.3497,-1.4644,-1.4336,-1.4487,-1.3692,-1.2975,-1.2469,-1.2067,-1.048,-0.93953,-0.88661,-0.887,-0.92488,-0.92488,-0.89929,-0.93571,-0.90679,-0.86748,-0.92565,-0.93407,-0.91541
8 | 1,-1.5141,-1.5034,-1.5444,-1.5876,-1.6176,-1.6399,-1.6636,-1.6259,-1.5211,-1.303,-0.90455,-0.53805,-0.28647,0.003158,0.25862,0.5071,0.71986,0.89223,1.0693,1.2137,1.428,1.5724,1.6858,1.7437,1.8054,1.6843,1.5227,1.5631,1.6179,1.6105,1.5942,1.595,1.5363,1.4105,1.2566,1.06,0.88835,0.71597,0.56877,0.4543,0.34807,0.2726,0.19184,0.13167,0.0716,0.010147,-0.027902,-0.080314,-0.11875,-0.15509,-0.18491,-0.19981,-0.25308,-0.28958,-0.32452,-0.36754,-0.40411,-0.44837,-0.49053,-0.5365,-0.56867,-0.59396,-0.63589,-0.6725,-0.71443,-0.74421,-0.78653,-0.81759,-0.84554,-0.87549,-0.91143,-0.9263,-0.94538,-0.95669,-0.97692,-0.969,0.38441,0.33876,-0.19019,-0.1995,0.0117,0.2394,0.16731,0.31586
9 | 2,0.59207,0.44457,0.33315,0.24549,0.13955,0.044638,0.02094,-0.11388,-0.10783,0.018303,0.011633,0.13882,0.44895,0.82988,1.1811,1.1814,1.0503,1.0986,1.1243,1.1451,1.0465,1.1601,0.41455,0.44331,0.50379,0.52585,0.55124,0.56292,0.56104,0.55971,0.57118,0.57371,0.60186,0.63237,0.66342,0.67118,0.69134,0.71961,0.67505,0.67053,0.66859,0.67796,0.71574,0.77874,0.91332,0.90228,0.93577,0.9102,0.878,0.878,0.87222,0.83834,0.816,0.7484,0.37423,-0.15895,-0.55215,-0.89098,-1.1398,-1.3485,-1.5066,-1.7092,-1.85,-1.9327,-1.9417,-1.9883,-2.0104,-2.023,-1.9847,-1.8947,-1.8351,-1.7101,-1.5952,-1.43,-1.2015,-1.0099,-0.82673,-0.70117,-0.58242,-0.43824,-0.2441,-0.095196,0.00043707,0.066628
10 | 1,-0.26791,-0.30235,-0.33159,-0.35838,-0.37922,-0.39602,-0.41353,-0.4342,-0.45235,-0.47073,-0.48532,-0.49349,-0.46606,-0.33387,-0.062468,0.2063,0.47836,0.68356,0.89676,1.0564,1.1203,1.2669,1.3847,1.4851,1.5405,1.6759,1.7064,1.7358,1.7273,1.6853,1.6123,1.5983,1.4574,1.2954,1.1652,1.0678,1.0789,-0.10011,-0.3219,-0.55186,-0.6486,-0.78007,-0.8131,-0.72555,-0.84567,-0.92262,-0.99835,-1.0592,-1.1171,-1.1673,-0.33474,-0.23038,-0.18416,-0.19,-0.19598,-0.21334,-3.8693,-0.21042,-0.21013,-0.23231,-0.24369,-0.26558,-0.2774,-0.28805,-0.30497,-0.29447,-0.31198,-0.30147,-0.30673,-0.11062,-0.64641,-0.48313,-0.34817,-0.21101,-0.0077508,0.15348,0.068853,0.085925,0.17654,0.25416,-3.8693,0.38782,0.42482,0.36389
11 | 1,-0.62947,-0.67075,-0.6922,-0.71807,-0.73797,-0.76145,-0.77998,-0.82269,-0.84879,-0.85783,-0.87736,-0.87736,-0.88675,-0.87844,0.05456,0.3707,0.6016,0.77997,1.034,1.2345,1.295,1.3879,1.6511,1.2782,0.96503,-7.2174,0.68803,0.60796,0.56644,0.58126,0.55309,0.58296,0.58868,0.59609,0.59016,0.56742,0.50515,0.45967,0.47806,0.42458,0.32325,0.15243,-0.063559,-0.21255,-0.3035,0.19191,0.29275,0.34006,0.35488,0.3581,0.35142,0.33437,0.31336,0.29656,0.27061,0.24763,0.21056,0.29275,0.16236,0.096079,0.059306,0.023717,-0.0079173,-0.047459,-0.12753,-0.075633,-0.24557,-0.28916,-0.3292,-0.39889,-0.45277,-0.50951,-0.53976,-0.55518,-0.57196,-0.53502,-0.60909,-0.59364,0.063118,0.03558,0.071909,0.28173,0.46086,0.69693
12 | 2,-0.21062,-0.11958,-0.14598,-0.089906,-0.13204,-0.11151,-0.088813,0.030626,-0.017302,-0.047656,-0.10309,0.12919,0.16546,0.23426,-0.028468,-0.013137,0.031719,0.084138,0.11467,0.18866,0.18431,0.17388,0.20604,0.25289,0.4567,0.55756,0.69637,0.78246,0.82381,0.91896,0.98008,0.87602,0.84983,0.77857,0.65694,0.5104,0.51147,0.66654,0.52685,0.47648,0.45241,0.49109,0.49109,0.45957,-5.7545,0.52542,0.5297,0.4825,0.43777,0.50309,0.47605,0.3975,0.37163,0.30574,0.22051,0.17301,0.13123,0.13427,0.10014,0.019471,-0.065536,-0.16265,-0.18166,-0.30384,-0.3526,-0.47602,-0.66837,-0.73466,-0.80224,-0.84626,-0.86886,-0.83196,-0.7124,-5.7545,-0.37701,-0.30384,-0.17902,-0.086608,0.013494,0.026472,0.168,0.21125,0.23208,0.3522
13 | 2,-0.032347,-0.022037,0.0094025,-0.099033,-0.060332,-0.011448,-0.090197,-0.0946,-0.079543,-0.20723,-0.32615,-0.36175,-0.33222,0.72642,0.72567,0.87659,0.92316,0.92856,0.92165,0.9424,0.97236,0.9689,0.99155,1.0267,1.006,1.015,1.0495,1.0628,1.0822,1.0612,1.077,1.0612,1.1012,1.1376,1.2113,1.2789,1.2731,1.3065,1.2525,1.3507,1.3016,1.4155,1.3784,1.4456,1.4656,1.4283,1.4955,-0.33765,-0.47085,-0.76959,-0.8716,-0.89754,-0.82157,-0.9567,-1.1077,-0.92331,-0.65271,-0.58771,-0.85598,-0.9493,-1.1322,-1.2293,-1.2565,-1.3293,-1.5015,-1.3002,-1.305,-1.2097,-1.1362,-1.131,-1.1455,-1.0281,-0.98108,-0.9209,-0.90373,-0.97627,-0.98108,-0.96663,-0.97747,-0.98521,-0.98349,-1.0404,-0.98976,-0.94063
14 | 1,-1.4502,-1.5111,-1.5375,-1.5927,-1.6312,-1.6804,-1.692,-1.7561,-1.8353,-1.8377,-1.8233,-1.4494,-0.90345,-0.46778,-0.09407,0.2806,0.48715,0.57041,0.62885,0.77055,0.81186,0.90265,0.96509,0.9803,1.0837,1.2221,1.2586,1.4248,1.5151,1.5991,1.6121,1.632,1.6064,1.5429,1.4751,1.347,1.3777,1.2341,1.0645,0.97024,0.91946,0.77536,0.70811,0.63445,0.54575,0.44472,0.36226,0.27099,0.20374,0.13289,0.090863,0.040426,0.040427,0.021213,-0.030024,-0.091668,-0.12289,-0.15651,-0.21175,-0.2718,-0.30542,-0.34289,-0.35346,-0.43031,-0.49756,-0.57922,-0.62245,-0.62085,-0.66088,-0.67048,-0.73293,-0.74134,-0.84941,-0.88744,-0.88344,-0.89304,-0.86382,-0.87343,-0.85782,0.020012,-0.098874,0.18453,0.42831,0.72572
15 | 1,-1.0381,-1.0775,-1.1015,-1.137,-1.1706,-1.2126,-1.2326,-1.277,-1.3338,-1.3612,-1.3971,-1.4211,-1.4363,-1.4583,-1.4583,0.24214,1.0183,1.4975,1.8754,2.1878,1.165,0.9618,0.99482,0.87171,0.68725,0.67419,0.67861,0.68821,0.82395,0.86018,0.79613,0.86311,0.80093,0.81502,0.81663,0.8309,0.82474,0.76027,0.73392,0.68122,0.44919,0.38573,0.33464,0.31121,0.28407,0.2329,0.17068,0.13603,0.079186,-0.007428,-0.069197,-0.12164,-0.17448,-0.23757,-0.29681,-0.39768,-0.45436,-0.48307,-0.50272,-0.52663,-0.55798,-0.58762,-0.64778,-0.71727,-0.76805,-0.82358,-0.89051,-0.91188,-0.94591,-0.99138,-1.0258,-1.0532,-1.0515,-1.0436,-1.0394,-1.0404,0.23125,1.4966,2.0412,2.4684,1.3244,1.0831,1.0854,1.2166
16 | 2,-0.29633,-0.52524,-0.64323,-0.66443,-0.46614,-4.3935,-0.47277,-0.45182,-0.24982,0.07162,0.18893,0.33016,0.48539,-4.3935,0.95231,1.079,1.3201,1.5858,1.7469,0.89952,0.66588,0.75802,0.75673,0.75415,0.75221,0.73736,0.75415,0.77866,0.80135,0.82246,0.83532,0.83017,0.81731,0.81216,0.80521,0.78962,0.8054,0.81699,0.7309,0.65169,0.65869,0.68435,0.67347,0.66258,0.63477,0.58158,0.48149,0.35381,0.27884,0.19572,0.1604,0.10765,0.032583,-0.032577,-0.083859,-0.1437,-0.19401,-0.23434,-0.66373,0.025263,0.035576,-0.044384,-0.22512,-0.3973,-0.55928,-0.68428,-0.79954,-0.84238,-0.98172,-1.1959,-1.3043,-1.2973,-1.2584,-1.2952,-1.2008,-1.0802,-0.94311,-0.78511,-0.59541,-0.40522,-0.28147,-0.10687,0.11478,0.37544
17 | 1,0.77854,0.74884,0.726,0.70376,0.64638,0.67266,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,0.82923,-1.0125,0.73562,0.71393,0.67929,0.63291,0.61466,-1.0125,0.56288,0.52297,0.55399,0.69676,0.92507,1.3198,-1.0125,1.6402,1.3246,1.0257,1.0129,0.95643,0.90079,0.86506,0.8383,0.80752,0.77123,0.71491,0.66193,0.61339,0.57297,0.53773,0.73631,0.97459,1.0644,1.3719,1.6176,1.528,1.3471,1.2011,-1.0125,1.2724,1.5788,1.5019,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125,-1.0125
18 | 1,-0.93323,-0.96281,-0.99211,-1.015,-1.0337,-1.0531,-1.066,-1.0724,-1.0926,-1.1014,-1.0974,-1.0916,-0.97201,-0.68381,-0.36689,-0.086642,0.17931,0.44555,0.68886,0.93444,1.1158,1.2486,1.3538,1.4833,1.5994,1.6935,1.7409,1.7101,1.7051,1.6123,1.5846,1.5476,1.4236,1.4457,1.4316,1.3931,1.2567,1.0706,0.72863,0.44953,0.29676,0.18429,0.081312,-0.028646,-0.12094,-0.17985,-0.26312,-0.32625,-0.37828,-0.42282,-0.45755,-0.51831,-0.56595,-0.61998,-0.65535,-0.69188,-0.72979,-0.76583,-0.81045,-0.85717,-0.89659,-0.93707,-0.96737,-0.99736,-1.0361,-1.0585,-1.0848,-1.1164,-1.1416,-1.1641,-1.1519,-1.045,-0.82806,-0.53709,-0.27085,-0.030895,0.22903,0.47759,0.63666,0.84297,0.99086,1.1245,1.197,1.3731
19 | 2,-0.5066,-0.47651,-0.39193,-0.35153,-0.3728,-0.35669,-0.33092,-0.24953,-0.13999,-0.038713,0.01566,0.070046,0.16914,0.19765,0.22327,0.24941,0.3108,0.32125,0.30035,0.27943,0.33796,0.37031,0.38803,0.42412,0.44908,0.41481,0.41857,0.37969,0.43383,0.45295,0.51983,0.456,0.50029,0.46209,0.41996,0.34465,0.18295,0.088201,0.055686,0.011713,0.055123,0.0028119,0.0015547,-6.1087,0.079336,0.077643,0.1479,0.205,0.21655,0.17314,0.17384,0.13931,0.10297,0.12994,0.15982,0.14209,0.26268,0.297,0.32683,0.40219,0.42065,0.46846,0.50962,0.51273,0.53759,0.55345,0.57277,-6.1087,0.45877,0.32334,0.2543,0.060756,-0.33092,-0.21819,-0.25488,-0.38247,-0.35813,-0.31967,-0.20619,-0.018576,0.05794,0.1156,0.15435,0.17791
20 | 2,-0.40837,-0.32777,-0.34288,-1.4984,-0.21999,-0.47757,-0.62553,-0.60179,-0.4906,-0.42711,-0.492,-0.4682,-0.46605,-0.49328,-0.13824,-0.028,-0.0025731,0.15329,0.08199,0.13191,-1.4848,0.45876,0.46868,0.55498,0.70724,0.77261,0.79337,1.0516,1.1644,1.3739,1.6467,1.7479,0.99273,0.92966,1.066,0.90018,0.89738,0.95912,0.96033,0.94228,0.99907,0.95311,0.95211,0.92405,0.89739,0.86286,0.905,0.95492,0.87828,0.9026,0.92685,0.81828,0.77472,0.85804,0.89418,0.85488,0.80019,0.71934,0.62987,0.47548,0.2323,-0.0051373,-0.11248,-0.24695,-0.33929,-0.46317,-0.62082,-0.74022,-0.83704,-0.90927,-0.95917,-2.275,-1.3826,-1.5678,-1.8879,-1.8499,-1.8403,-1.6429,-1.2009,-1.4552,-1.5726,-1.5181,-1.722,-1.8265
21 |
--------------------------------------------------------------------------------
/Signal-Alignment/data/SonyAIBORobotSurfaceII_TRAIN:
--------------------------------------------------------------------------------
1 | 2,-0.77065,-1.2791,-0.26209,1.5178,2.2806,1.0092,-0.51635,-1.5334,-0.77065,1.0092,2.5348,2.7891,1.772,-0.26209,-1.5334,-2.0419,-1.5334,-0.51635,-0.26209,-0.26209,-0.51635,-0.51635,-0.26209,-0.26209,-0.26209,-0.0078248,0.24645,0.24645,0.24645,0.24645,-0.0078248,-0.26209,-0.51635,-0.26209,-0.0078248,0.24645,0.24645,-0.0078248,-0.26209,-0.0078248,-0.0078248,-0.26209,-0.77065,-0.77065,-0.26209,-0.26209,-0.77065,0.50071,1.2635,2.2806,2.2806,1.2635,0.24645,-0.51635,-1.2791,-1.2791,-0.77065,-0.26209,-0.0078248,-0.0078248,-0.51635,-0.26209,-0.0078248,-0.0078248,0.50071
2 | 1,-0.69146,0.037369,0.28031,0.28031,0.52324,0.52324,0.52324,0.52324,0.28031,-0.69146,-0.44849,0.76617,1.7379,-0.20556,-2.392,-1.906,0.037369,1.252,2.2238,1.9808,1.0091,0.52324,0.037369,-0.44849,-0.44849,-0.44849,-0.69146,-0.93429,-0.69146,-0.44849,-0.44849,-0.69146,-0.69146,-0.44849,-0.20556,0.28031,0.28031,0.52324,0.28031,0.28031,0.28031,-0.44849,-1.1773,-0.93429,0.28031,0.76617,0.52324,-0.20556,0.037369,0.76617,1.7379,1.9808,1.0091,-1.906,-1.906,0.76617,1.7379,0.037369,-2.392,-1.4202,-0.93429,-0.44849,0.52324,0.28031,-0.20556
3 | 1,0.022305,-0.1388,-0.29991,-0.78321,0.18342,1.1501,0.50563,0.82784,0.18342,-0.94435,-0.78321,0.34453,1.7945,2.2778,-0.1388,-1.5888,-0.46104,-0.46104,-0.29991,-0.1388,-0.1388,-0.78321,-0.78321,-0.29991,0.022305,0.18342,0.022305,-0.1388,0.022305,0.18342,0.022305,0.022305,-0.29991,-0.1388,0.022305,0.022305,-0.1388,0.022305,0.022305,0.18342,0.34453,0.022305,-0.62208,-1.5888,-1.1055,-0.62208,-0.46104,0.34453,1.6334,2.9222,3.4055,2.6,-0.78321,-2.0721,-2.2332,-0.62208,0.18342,0.34453,-0.29991,-0.46104,-0.46104,-0.62208,0.022305,0.50563,0.34453
4 | 1,0.026081,0.026081,0.30868,0.30868,-0.53909,-1.6695,-0.82172,0.87385,1.439,0.30868,0.30868,1.1564,1.1564,0.026081,-0.2565,-0.2565,-0.2565,0.026081,0.026081,-0.82172,-0.2565,-0.53909,-0.53909,-0.53909,0.026081,-0.53909,0.026081,-0.2565,0.30868,0.30868,0.026081,0.026081,-0.2565,0.026081,0.30868,0.30868,0.026081,0.026081,-0.2565,0.026081,0.026081,0.026081,0.026081,-1.1042,-1.9521,-1.1042,-0.53909,-0.2565,2.0042,3.4171,3.6997,2.2868,-2.2346,-1.3868,-1.6695,0.026081,0.026081,-0.2565,-0.2565,-0.53909,0.30868,0.30868,0.026081,-0.2565,-0.2565
5 | 2,-0.12247,0.1263,0.37505,0.1263,0.37505,0.1263,0.1263,-0.12247,-0.86878,-0.61998,-0.12247,0.62381,1.3701,2.1164,1.3701,-0.37123,-1.615,-1.1174,0.62381,1.8676,2.1164,1.1213,-0.12247,-1.3662,-1.8638,-1.3662,-0.61998,-0.61998,-0.61998,-0.86878,-1.1174,-1.1174,-0.61998,-0.37123,0.37505,0.62381,0.62381,0.37505,0.1263,-0.12247,-0.37123,-0.12247,-0.12247,0.1263,0.37505,0.87257,0.62381,0.37505,-0.37123,-0.86878,-0.61998,0.37505,-0.37123,-1.615,-1.8638,-0.61998,0.37505,1.6188,2.1164,2.1164,1.6188,0.37505,-0.61998,-1.1174,-1.1174
6 | 2,-0.335,0.016207,0.016207,-0.335,-0.6862,0.71863,0.71863,0.016207,-0.6862,-0.335,0.71863,1.0698,1.0698,0.71863,0.36743,0.016207,-0.6862,-1.0375,-0.6862,-0.6862,-0.335,-0.6862,-0.6862,0.016207,0.016207,0.016207,0.016207,0.016207,0.016207,0.016207,-0.335,-0.335,-0.335,0.016207,0.016207,0.016207,-0.335,0.016207,-0.335,-0.335,-0.335,-0.6862,-1.0375,0.016207,1.0698,0.016207,-2.0911,-0.6862,1.7722,4.2307,3.5283,2.1234,-0.335,-1.7398,-1.7398,-1.0375,-0.335,0.016207,0.016207,-0.335,-0.335,0.016207,0.36743,0.71863,0.36743
7 | 2,-0.19349,0.058044,0.56112,1.5673,2.3219,1.3157,-0.44502,-1.7028,-1.7028,0.56112,2.0703,2.5734,0.81266,-0.94803,-1.4512,-1.4512,-0.94803,-0.6966,-0.6966,-0.6966,-0.94803,-0.6966,-0.19349,0.058044,0.058044,0.058044,0.30959,0.30959,0.56112,0.058044,0.058044,-0.19349,-0.19349,-0.19349,0.058044,-0.19349,0.058044,0.058044,0.058044,-0.19349,-1.1996,-1.9542,-0.6966,1.0642,1.5673,0.81266,-0.19349,0.56112,1.3157,1.8188,1.5673,0.81266,-0.44502,-1.4512,-1.9542,-1.1996,-0.44502,0.058044,0.058044,-0.19349,-0.19349,-0.19349,0.058044,0.30959,0.30959
8 | 2,-0.82536,-0.54879,-0.54879,0.0042513,2.2164,3.046,1.3869,-0.54879,-1.6549,-0.27227,0.83383,2.493,2.2164,0.55731,-0.82536,-1.6549,-1.6549,-1.1018,-0.54879,-0.54879,-0.27227,0.0042513,0.0042513,-0.27227,-0.27227,-0.27227,0.0042513,0.28079,0.0042513,0.0042513,0.0042513,-0.27227,-0.27227,-0.27227,-0.27227,0.0042513,0.0042513,0.0042513,0.0042513,-0.27227,-0.54879,-0.27227,-0.27227,-0.54879,-0.27227,0.55731,0.28079,-0.27227,0.55731,1.3869,2.493,2.2164,0.28079,-0.54879,-1.3783,-1.6549,-1.3783,-0.54879,0.0042513,0.28079,0.0042513,-0.54879,-0.27227,0.0042513,0.55731
9 | 1,-0.17112,0.21243,0.020648,0.21243,0.020648,-0.17112,0.020648,0.020648,0.21243,-0.36289,-0.74639,-0.17112,1.3631,2.5137,-0.17112,-1.8971,-2.0888,-0.74639,0.59597,1.5548,1.5548,0.97951,0.78774,0.78774,0.020648,-0.5547,-0.74639,-0.93819,-0.93819,-0.74639,-0.5547,-0.36289,-0.5547,-0.17112,0.020648,0.4042,0.21243,0.21243,0.21243,0.21243,0.020648,0.020648,0.020648,0.020648,0.21243,0.020648,-0.17112,-0.17112,-0.17112,0.020648,0.020648,-0.17112,-1.13,-0.93819,-0.36289,-0.36289,-0.36289,0.78774,1.7466,2.8972,2.5137,1.3631,-1.7053,-2.2806,-1.8971
10 | 2,-0.746,-0.51832,0.39225,1.3028,1.9858,1.0752,-0.51832,-1.4289,-0.97355,0.39225,1.9858,1.9858,1.7581,1.0752,-0.51832,-2.1118,-1.8841,-0.746,-0.29068,-0.29068,-0.746,-0.51832,-0.51832,-0.51832,-0.063043,0.16461,0.39225,0.61989,0.39225,0.16461,-0.063043,-0.063043,-0.29068,-0.29068,-0.29068,-0.29068,-0.063043,-0.063043,-0.063043,-0.063043,-0.063043,-0.746,-0.746,-0.51832,-0.063043,-0.51832,-0.51832,0.61989,1.7581,2.6687,2.441,1.0752,-0.51832,-1.4289,-1.8841,-1.4289,-0.97355,-0.063043,0.39225,0.39225,-0.063043,-0.29068,-0.063043,0.39225,0.39225
11 | 2,-0.485,-0.485,0.28392,1.5654,3.1032,1.8217,-0.2287,-2.0228,-1.5102,0.54022,2.3343,2.3343,0.79652,-0.99755,-1.5102,-1.7666,-1.2539,-0.74135,-0.74135,-0.74135,-0.74135,-0.485,0.027599,0.027599,0.027599,0.027599,0.027599,0.28392,0.28392,0.28392,0.027599,-0.485,-0.2287,0.027599,-0.2287,0.027599,0.027599,0.027599,-0.2287,-0.485,-0.74135,-0.99755,-0.74135,0.54022,1.8217,1.3091,0.027599,0.28392,1.0528,1.3091,1.3091,0.54022,-0.485,-0.99755,-1.5102,-1.2539,-0.485,-0.2287,0.027599,-0.2287,-0.2287,-0.2287,0.28392,0.54022,0.54022
12 | 2,-0.20316,-0.45711,0.5587,1.3205,2.5903,1.5745,-0.20316,-1.7269,-0.96494,0.050787,1.5745,2.0824,1.3205,-0.20316,-1.4729,-1.9808,-1.4729,-0.7111,-0.20316,-0.20316,-0.7111,-0.45711,-0.20316,0.050787,0.30475,0.30475,0.050787,0.30475,0.050787,-0.20316,-0.20316,-0.20316,-0.20316,0.050787,0.050787,0.050787,-0.20316,-0.20316,-0.20316,-0.45711,-0.20316,-0.7111,-0.7111,0.30475,1.0666,0.30475,0.050787,0.30475,1.5745,2.5903,2.3363,0.81264,-0.96494,-1.9808,-1.9808,-1.4729,-0.7111,0.050787,0.050787,-0.20316,-0.20316,-0.20316,0.050787,0.30475,0.30475
13 | 1,-0.39112,-0.18102,0.029089,-0.39112,-0.39112,0.23921,0.44931,0.23921,0.44931,0.029089,-0.60127,-0.18102,1.2897,1.9201,0.86953,-1.8619,-1.8619,-0.81129,0.23921,1.9201,2.5504,1.4998,0.44931,-0.60127,-0.60127,-1.0214,-0.39112,-0.18102,-0.39112,-1.0214,-1.2316,-0.60127,-0.60127,-0.39112,-0.18102,-0.18102,0.44931,0.44931,0.44931,0.44931,0.029089,-0.39112,-0.39112,-0.18102,-0.18102,-0.60127,-0.60127,-0.18102,0.23921,0.23921,-0.18102,0.23921,2.1302,1.71,-1.0214,-2.4922,0.23921,1.9201,1.9201,0.86953,0.44931,-1.2316,-1.6517,-1.0214,0.23921
14 | 1,0.2938,0.75395,0.52387,0.06371,-0.16636,-0.39644,-0.39644,-0.16636,-0.16636,-0.16636,-0.16636,-0.16636,0.2938,0.52387,-0.16636,-0.62655,-2.007,-1.3168,0.2938,0.52387,0.75395,2.3645,3.0547,3.0547,1.2141,-2.2371,-2.6972,-0.85654,-0.16636,0.98402,-0.62655,-1.3168,0.06371,0.06371,0.2938,-0.16636,-0.16636,0.06371,0.2938,0.2938,-0.16636,-0.16636,0.06371,0.06371,0.2938,0.06371,0.06371,-0.16636,0.2938,0.2938,0.06371,-0.16636,0.06371,0.2938,0.06371,-0.16636,-0.62655,-1.0867,0.06371,1.6743,0.75395,-0.85654,-2.007,-1.3168,0.98402
15 | 1,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,-0.18525,0.0058773,0.0058773,0.38815,-0.56754,-0.94976,-0.18525,1.5349,2.4906,0.0058773,-2.0965,-1.7143,-0.37638,0.96154,1.7261,1.7261,1.5349,0.96154,0.0058773,-0.37638,-0.56754,-0.56754,-0.94976,-0.94976,-0.7586,-0.7586,-0.56754,0.0058773,0.19702,0.38815,0.0058773,0.0058773,0.19702,0.19702,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,0.0058773,-0.18525,-0.37638,0.0058773,-0.37638,-1.1409,-0.94976,0.19702,-0.18525,-0.56754,0.19702,1.9172,2.8728,2.2995,0.96154,-2.0965,-2.2877,-1.1409
16 | 1,-0.14213,-0.58208,-0.36208,-0.14213,0.077823,0.29779,0.51774,0.51774,0.7377,0.077823,-0.80194,-0.58208,1.1776,2.9372,0.95765,-2.5616,-2.3416,-1.2419,0.95765,2.0574,2.0574,1.1776,0.51774,-0.36208,-0.80194,-0.58208,-0.58208,-0.58208,-0.36208,-0.36208,-0.36208,-0.36208,-1.0219,-0.80194,-0.36208,0.29779,0.51774,0.51774,0.29779,0.29779,-0.36208,-0.80194,-0.58208,0.077823,0.077823,0.51774,0.29779,0.077823,0.29779,0.51774,1.3976,1.6175,1.3976,0.95765,-1.6818,-2.3416,-0.14213,0.51774,-0.14213,-1.2419,-0.80194,-0.58208,-0.36208,0.51774,0.077823
17 | 2,-0.69721,-0.47059,-0.24401,1.3421,2.9281,2.9281,0.8889,-1.3769,-1.83,-0.69721,0.8889,2.0218,1.7952,0.43574,-0.9237,-1.6035,-1.3769,-0.69721,-0.24401,-0.47059,-0.69721,-0.47059,-0.24401,-0.24401,-0.24401,-0.24401,-0.017432,0.20916,0.20916,0.20916,-0.017432,-0.24401,-0.24401,-0.24401,-0.017432,-0.017432,-0.017432,-0.24401,-0.24401,-0.47059,-0.24401,-0.47059,-0.24401,0.20916,0.66232,-0.24401,-1.1503,-0.47059,1.3421,2.2484,2.475,1.3421,-0.24401,-1.1503,-1.3769,-0.9237,-0.017432,0.20916,-0.24401,-0.47059,-0.017432,-0.017432,-0.24401,-0.24401,-0.017432
18 | 2,-0.53461,-0.80827,-0.26099,0.83348,2.4752,1.6543,-0.26099,-1.3554,-1.0818,0.55987,2.2016,3.0224,1.6543,-0.26099,-2.1763,-2.4499,-1.0818,-0.26099,0.012623,-0.26099,-0.53461,-0.53461,-0.26099,-0.53461,-0.53461,-0.26099,0.012623,0.28625,0.28625,0.012623,0.012623,-0.26099,-0.26099,-0.26099,-0.26099,0.012623,0.012623,0.012623,-0.26099,0.012623,0.012623,-0.53461,-0.53461,-0.26099,0.012623,-0.26099,0.012623,0.83348,1.3807,2.2016,2.2016,0.55987,-0.26099,-0.80827,-1.3554,-1.3554,-0.26099,0.012623,0.012623,-0.26099,-0.53461,-0.53461,0.012623,0.55987,0.83348
19 | 2,-0.27502,-0.5233,-0.77161,-0.026742,1.4629,2.4561,1.4629,-0.27502,-1.2681,-0.77161,0.96638,2.2078,1.7112,0.22155,-1.0198,-1.5164,-1.5164,-1.2681,-0.5233,-0.026742,0.22155,-0.026742,-0.77161,-1.0198,-0.5233,-0.026742,0.46983,0.7181,0.46983,-0.026742,-0.026742,-0.27502,-0.27502,-0.27502,-0.026742,-0.026742,-0.026742,0.22155,0.46983,0.46983,-0.026742,-0.27502,-0.77161,-0.77161,-0.77161,-1.0198,-0.77161,-0.026742,0.96638,1.9595,2.9526,2.7043,0.96638,-0.77161,-1.2681,-1.0198,-1.0198,-0.5233,-0.27502,-0.026742,-0.026742,-0.27502,-0.5233,-0.27502,0.46983
20 | 2,-0.28182,-0.53982,-0.02382,1.5242,2.5562,1.5242,-0.53982,-1.8299,-1.0558,0.4922,2.2982,2.5562,0.7502,-0.28182,-1.3138,-2.0878,-1.3138,-0.28182,-0.28182,-0.28182,-0.53982,-0.28182,-0.79787,-0.53982,-0.02382,0.2342,0.4922,0.4922,-0.02382,-0.02382,-0.02382,-0.28182,-0.53982,-0.28182,-0.28182,0.2342,0.2342,-0.28182,-0.28182,-0.28182,-0.28182,-0.79787,-0.79787,-0.53982,0.2342,0.4922,-0.02382,0.7502,1.5242,2.0402,2.5562,1.0082,-0.53982,-1.3138,-1.5719,-1.3138,-0.28182,-0.02382,-0.02382,-0.02382,-0.53982,-0.53982,-0.02382,0.4922,0.7502
21 | 2,-0.29566,-0.97002,-0.97002,0.37866,1.3901,1.053,0.041492,-0.29566,0.041492,1.3901,2.4016,2.4016,0.37866,-0.97002,-1.9815,-1.9815,-0.63281,0.041492,0.041492,0.041492,-0.29566,-0.63281,0.041492,0.37866,0.71581,0.37866,0.041492,-0.29566,-0.29566,-0.29566,0.041492,-0.29566,-0.29566,-0.29566,0.37866,0.37866,0.041492,-0.29566,-0.63281,-0.29566,0.37866,0.71581,0.041492,-0.29566,0.041492,0.37866,-0.29566,-0.63281,0.37866,1.053,2.0644,2.7387,1.3901,0.041492,-1.307,-2.6557,-2.3187,-1.307,0.041492,0.041492,-0.29566,-0.63281,-0.29566,0.041492,0.71581
22 | 2,-0.43617,-0.43617,0.032439,1.4383,2.1412,1.4383,-0.43617,-1.6078,-1.1391,0.73537,2.1412,2.1412,0.73537,-0.43617,-1.3734,-1.6078,-1.1391,-0.20187,-0.20187,-0.20187,-0.67052,-0.43617,-0.43617,-0.67052,-0.43617,0.032439,0.26676,0.50106,0.26676,0.50106,0.032439,-0.20187,-0.20187,-0.20187,0.032439,0.032439,0.032439,0.26676,0.73537,0.50106,0.032439,-1.1391,-1.3734,-0.90473,-0.43617,-0.43617,0.26676,0.73537,1.9069,2.6098,2.6098,1.204,-0.90473,-1.3734,-1.3734,-1.1391,-0.90473,-0.20187,0.26676,-0.43617,-0.67052,-0.20187,-0.20187,0.26676,0.26676
23 | 1,0.023032,-0.16413,0.023032,0.023032,-0.16413,-0.35129,-0.35129,0.2102,0.39736,-0.53848,-0.91276,0.023032,1.5203,2.4561,0.58453,-2.4101,-2.2229,-0.72557,0.77169,1.5203,1.7075,1.3332,0.95885,0.2102,-0.91276,-0.91276,-0.53848,-0.35129,-0.16413,-0.35129,-0.53848,-0.35129,-0.35129,-0.35129,-0.16413,0.2102,0.2102,0.2102,0.2102,0.2102,0.023032,-0.16413,0.023032,0.2102,0.2102,0.023032,0.023032,-0.16413,0.023032,-0.16413,0.023032,-0.35129,-0.91276,-0.72557,0.2102,0.2102,-0.53848,0.2102,1.5203,2.6433,2.269,1.3332,-2.2229,-2.4101,-1.2871
24 | 1,0.0075404,0.0075404,-0.23772,-0.48298,-0.23772,-0.23772,-0.48298,-0.48298,0.0075404,0.25282,-0.72828,-1.2188,-0.48298,1.4791,0.49808,-0.97345,-0.23772,1.2339,0.9886,0.0075404,-0.48298,0.0075404,0.49808,0.0075404,-0.23772,0.0075404,0.25282,0.25282,-0.23772,0.0075404,-0.23772,0.0075404,0.25282,0.25282,0.0075404,0.0075404,0.0075404,0.0075404,0.0075404,0.0075404,0.0075404,0.0075404,-0.48298,-0.97345,-0.48298,0.25282,0.0075404,0.49808,-0.23772,-0.48298,0.9886,2.2149,2.9507,1.2339,-2.6903,-3.4262,-1.9545,-0.23772,1.7244,2.4602,1.4791,0.25282,-0.48298,-0.97345,-0.72828
25 | 1,0.033139,0.033139,0.033139,-0.13258,0.033139,0.033139,0.19887,0.033139,0.033139,-0.2983,-0.79545,-0.79545,0.36459,1.5246,0.86174,-1.2926,-1.2926,-0.2983,0.5303,1.6903,2.0218,1.3589,0.36459,-0.46404,-0.6297,-0.2983,-0.13258,-0.2983,-0.2983,-0.6297,-0.6297,-0.96119,-0.79545,-0.46404,-0.13258,0.19887,0.19887,0.19887,0.19887,0.36459,-0.2983,-0.46404,-0.13258,0.5303,0.19887,-0.13258,-0.13258,0.19887,0.36459,0.19887,0.19887,0.86174,1.3589,0.36459,-2.287,-2.4526,-0.2983,1.5246,2.3532,2.3532,1.8561,-0.79545,-2.7841,-1.4583,-0.79545
26 | 2,-0.28557,-0.28557,-0.63579,-0.63579,0.064651,0.064651,-0.28557,-0.28557,0.064651,0.41489,-0.28557,0.064651,0.064651,-0.63579,-0.28557,-0.63579,-0.98607,-0.63579,1.1153,1.1153,1.4655,1.4655,0.41489,0.41489,0.41489,1.1153,1.1153,-0.28557,-0.63579,-0.63579,-0.98607,-1.3361,-0.28557,0.064651,0.064651,-0.28557,-0.63579,-0.63579,0.064651,0.064651,0.064651,-0.28557,-0.28557,0.41489,0.41489,0.41489,0.41489,0.76511,0.76511,0.41489,0.064651,0.064651,0.064651,0.064651,-0.28557,0.064651,-0.63579,0.41489,2.166,3.2167,1.4655,-2.387,-4.138,-1.6864,0.41489
27 | 2,-0.47719,-0.47719,0.0036952,1.4464,2.4082,1.2059,-0.71768,-1.9198,-0.95803,0.72504,2.4082,2.8891,1.2059,-0.71768,-2.4008,-1.9198,-0.71768,-0.23675,-0.47719,-0.47719,-0.47719,-0.47719,-0.47719,-0.47719,-0.23675,0.4846,0.72504,0.4846,0.0036952,-0.23675,-0.23675,-0.23675,-0.23675,-0.23675,0.0036952,0.0036952,0.24415,0.24415,-0.23675,-0.23675,0.0036952,-0.47719,-0.47719,-0.47719,-0.23675,-0.23675,-0.47719,0.24415,0.96549,2.1677,2.4082,1.4464,0.24415,-0.71768,-1.439,-0.95803,-0.47719,-0.23675,-0.23675,-0.47719,-0.47719,-0.23675,0.0036952,0.4846,0.4846
28 |
--------------------------------------------------------------------------------
/Signal-Alignment/data/SonyAIBORobotSurface_TRAIN:
--------------------------------------------------------------------------------
1 | 2,0.99364,2.2738,2.9139,2.2738,1.6337,0.14021,-0.71322,-1.1399,-0.92658,-0.49987,-0.92658,-1.5667,-1.78,-1.9934,-2.2067,-1.78,-1.3533,-0.71322,-0.49987,-0.28651,0.35356,0.35356,0.78028,0.78028,0.78028,0.56692,0.56692,0.35356,0.56692,0.56692,0.56692,0.35356,0.35356,0.14021,0.14021,0.35356,0.14021,0.35356,0.56692,0.78028,0.78028,1.207,1.4204,1.4204,0.35356,-0.28651,-0.71322,-0.92658,-0.92658,-0.71322,-0.71322,-1.1399,-1.5667,-1.3533,-1.1399,-0.49987,0.14021,0.14021,0.14021,0.14021,0.14021,0.35356,0.35356,0.14021,-0.073151,-0.073151,-0.073151,0.14021,0.14021,-0.073151
2 | 1,-0.060775,-0.34439,1.9246,3.6263,1.9246,0.50646,-0.62801,-1.1953,-0.91163,0.22284,1.3573,0.50646,-1.1953,-2.3297,-2.0461,-0.91163,-0.34439,-0.34439,-0.91163,-0.91163,-0.34439,0.22284,0.22284,0.50646,0.79008,0.79008,0.79008,0.79008,0.79008,0.79008,1.0737,0.79008,0.50646,0.22284,0.22284,0.22284,0.22284,-0.060775,0.79008,1.0737,0.79008,0.50646,0.22284,0.22284,-0.34439,-1.1953,-2.0461,-1.4789,-0.34439,0.50646,0.22284,-1.1953,-2.0461,-1.7625,-1.1953,-0.34439,0.50646,0.79008,0.50646,0.22284,-0.060775,-0.060775,-0.060775,-0.34439,-0.34439,-0.060775,0.22284,0.22284,-0.060775,-0.34439
3 | 2,0.61165,1.3174,2.0231,2.2584,2.0231,1.7879,0.3764,-0.79984,-1.5056,-1.9761,-1.2703,-0.79984,-1.2703,-1.5056,-1.9761,-1.5056,-1.0351,-0.79984,-0.32935,-0.32935,0.14115,0.3764,0.61165,0.84689,0.61165,0.61165,0.3764,0.3764,0.14115,0.14115,0.14115,0.14115,0.14115,0.3764,0.14115,0.14115,0.14115,0.61165,1.0821,1.3174,0.3764,0.3764,1.5526,2.0231,1.5526,0.14115,-0.5646,-1.2703,-1.5056,-0.79984,-0.094099,-0.094099,-0.79984,-1.5056,-1.7408,-1.0351,-0.094099,0.61165,0.61165,0.3764,0.3764,0.14115,0.14115,-0.094099,-0.32935,-0.5646,-0.5646,-0.5646,-0.32935,-0.094099
4 | 2,0.6445,1.2038,1.9495,2.1359,2.1359,1.3902,0.45807,-0.66048,-1.2198,-1.4062,-1.2198,-0.8469,-0.8469,-1.4062,-1.779,-1.5926,-1.2198,-0.8469,-0.47405,-0.47405,-0.28763,0.085223,0.27165,0.45807,0.45807,0.45807,0.45807,0.45807,0.27165,0.085223,0.085223,0.085223,0.085223,0.27165,0.085223,0.085223,0.085223,0.6445,1.0173,1.3902,1.2038,1.2038,1.763,2.1359,1.763,0.6445,-0.1012,-0.66048,-1.2198,-1.2198,-0.66048,-0.66048,-1.4062,-1.9655,-1.779,-1.4062,-0.47405,0.085223,0.45807,0.27165,-0.28763,-0.1012,0.085223,0.27165,0.085223,-0.1012,-0.1012,-0.1012,-0.1012,-0.1012
5 | 1,0.8053,1.4248,1.2183,1.8377,1.4248,0.59882,-0.64011,-0.8466,-0.8466,-0.43362,-0.43362,-1.2596,-1.879,-2.292,-2.0855,-1.0531,-0.64011,-0.8466,-0.8466,-0.22714,0.39233,0.8053,0.39233,0.18584,-0.020649,-0.020649,0.18584,0.39233,0.39233,-0.020649,-0.020649,-0.020649,-0.020649,0.39233,0.39233,0.39233,0.59882,0.8053,0.59882,0.59882,0.18584,-0.020649,0.18584,1.8377,2.4572,1.4248,0.39233,-1.2596,-1.2596,-0.43362,0.18584,-0.22714,-1.2596,-2.0855,-2.0855,-1.879,-1.0531,-0.43362,-0.22714,-0.22714,-0.020649,0.39233,1.0118,1.0118,1.0118,1.0118,0.59882,0.59882,0.39233,0.39233
6 | 2,1.2042,2.5392,2.5392,2.3485,1.9671,1.0135,-0.32149,-1.0843,-1.4658,-1.4658,-1.0843,-1.2751,-1.2751,-1.2751,-1.2751,-1.2751,-1.0843,-0.89363,-0.5122,-0.32149,-0.13077,0.44137,0.44137,0.25065,0.059938,0.44137,0.44137,0.25065,0.25065,0.25065,0.44137,0.44137,0.44137,0.25065,0.25065,-0.13077,0.44137,1.0135,1.0135,1.0135,1.2042,1.3949,1.5856,1.2042,0.25065,-0.32149,-0.70291,-1.0843,-1.2751,-0.70291,-0.5122,-1.0843,-1.6565,-1.8472,-1.4658,-0.70291,0.059938,0.25065,0.25065,0.059938,0.059938,0.25065,0.25065,0.059938,-0.32149,-0.13077,-0.13077,0.059938,0.059938,0.059938
7 | 2,1.1821,2.0396,2.0396,1.8252,0.96773,-0.10412,-0.74723,-1.3903,-1.6047,-1.176,-0.9616,-1.176,-1.6047,-1.8191,-1.8191,-1.3903,-0.9616,-0.9616,-0.74723,-0.31849,0.11025,0.32462,0.53899,0.32462,0.32462,0.32462,0.53899,0.32462,0.11025,0.11025,0.32462,0.32462,0.32462,-0.10412,-0.10412,-0.10412,0.32462,0.96773,1.1821,0.75336,1.1821,1.8252,2.0396,1.3965,-0.10412,-0.31849,-1.176,-1.176,-0.9616,-0.53286,0.32462,-0.53286,-1.6047,-2.0335,-1.6047,-0.53286,0.32462,0.53899,0.53899,0.53899,0.75336,0.75336,0.53899,0.32462,-0.10412,-0.10412,0.11025,0.32462,0.53899,0.53899
8 | 2,1.3424,2.0666,2.0666,2.0666,0.98026,0.25606,-0.6492,-1.1923,-1.3734,-1.3734,-1.0113,-1.0113,-1.5544,-1.9166,-1.9166,-1.5544,-1.1923,-0.83025,-0.6492,-0.28709,-0.10604,0.25606,0.43711,0.43711,0.43711,0.43711,0.43711,0.25606,0.25606,0.25606,0.25606,-0.10604,0.075007,0.25606,0.075007,-0.10604,0.075007,0.25606,0.61816,0.98026,1.5234,2.0666,1.8855,1.1613,-0.10604,-0.6492,-1.0113,-1.1923,-1.3734,-1.0113,-0.46815,-0.83025,-1.3734,-1.7355,-1.0113,-0.46815,0.25606,0.61816,0.43711,0.43711,0.43711,0.61816,0.61816,0.43711,0.43711,0.25606,0.25606,0.43711,0.79921,0.79921
9 | 2,0.93054,1.6939,2.4572,2.4572,1.185,-0.087238,-1.105,-1.3595,-1.6139,-0.85057,-0.59613,-1.105,-1.6139,-1.8683,-1.3595,-1.105,-0.85057,-0.85057,-0.85057,-0.59613,-0.087238,0.16721,0.42165,0.67609,0.67609,0.67609,0.67609,0.67609,0.42165,0.16721,0.42165,0.16721,0.16721,0.16721,-0.087238,0.16721,0.16721,0.16721,-0.34168,0.16721,1.185,1.9483,2.4572,1.4394,0.16721,-0.59613,-1.105,-0.85057,-0.59613,-0.087238,-0.087238,-1.105,-1.8683,-1.8683,-1.3595,-0.34168,0.42165,0.42165,-0.087238,0.16721,0.42165,0.93054,0.67609,0.67609,0.42165,0.16721,0.16721,0.16721,-0.34168,-0.087238
10 | 1,-0.33813,0.01514,1.075,1.7815,1.075,0.01514,-1.0447,-2.1045,-1.398,-0.33813,1.075,0.36841,-0.69141,-1.7512,-1.7512,-1.0447,-0.33813,-0.33813,0.36841,0.36841,0.72169,1.075,0.72169,1.4282,1.075,1.075,0.72169,0.72169,0.36841,0.36841,0.36841,0.01514,0.01514,-0.33813,-0.33813,-0.33813,0.01514,-0.33813,-0.33813,0.36841,0.72169,1.075,1.075,-1.0447,-1.0447,0.01514,0.36841,0.72169,-0.33813,-2.1045,-1.7512,-1.7512,-2.4578,-2.1045,-0.69141,0.72169,1.7815,2.1348,1.075,0.01514,-0.33813,-0.33813,0.01514,0.01514,0.36841,0.36841,0.36841,0.36841,0.36841,0.01514
11 | 2,0.7825,1.4803,2.178,2.178,2.3525,1.8292,0.95694,-0.4386,-1.1364,-1.4853,-1.8341,-1.6597,-1.4853,-1.3108,-1.3108,-1.4853,-1.4853,-1.1364,-0.4386,0.084729,0.084729,0.25917,0.25917,0.43361,0.43361,0.43361,0.25917,0.25917,0.25917,0.084729,0.25917,0.25917,0.25917,0.25917,0.25917,0.25917,-0.089713,-0.4386,0.084729,-0.089713,0.25917,0.60806,1.3058,1.8292,1.8292,1.1314,0.43361,-0.26416,-0.78748,-1.1364,-0.96193,-1.1364,-1.4853,-1.6597,-1.4853,-1.1364,-0.4386,0.25917,0.43361,0.25917,0.084729,0.084729,0.25917,0.43361,0.084729,0.084729,-0.089713,0.084729,0.25917,0.43361
12 | 1,1.0807,0.027094,-0.18363,1.5022,2.7665,1.0807,-0.18363,-1.0265,-1.2373,-0.60509,0.23782,-0.39436,-1.448,-1.8695,-1.8695,-1.0265,-0.39436,-0.39436,-0.39436,-0.39436,0.23782,0.87,0.87,1.0807,1.0807,1.2915,1.2915,1.0807,0.65928,0.44855,0.23782,0.027094,-0.18363,-0.18363,-0.18363,-0.60509,-0.60509,-1.0265,-0.81582,-1.0265,-1.6587,-1.6587,-0.18363,1.2915,1.7129,0.65928,-0.39436,-0.81582,-1.0265,-0.39436,0.23782,0.027094,-1.0265,-1.8695,-2.0802,-1.0265,0.23782,1.5022,1.2915,0.87,0.44855,0.027094,0.23782,0.65928,0.65928,0.44855,0.027094,0.44855,0.65928,0.87
13 | 2,0.85996,2.1273,2.7609,2.9721,2.1273,1.0712,-0.19613,-0.61857,-1.2522,-1.2522,-1.041,-1.2522,-1.2522,-1.4634,-1.2522,-1.041,-0.82978,-0.82978,-1.2522,-0.61857,-0.19613,0.2263,0.2263,0.2263,0.015087,0.2263,0.015087,0.015087,0.015087,-0.19613,0.015087,0.2263,0.015087,0.015087,0.2263,-0.19613,0.015087,0.64874,0.64874,0.64874,1.2824,1.7048,1.7048,1.0712,0.015087,-0.61857,-1.041,-1.2522,-1.041,-0.40735,0.015087,-0.61857,-1.8859,-1.8859,-1.2522,-0.40735,0.015087,0.43752,0.43752,0.2263,0.2263,0.43752,0.43752,0.015087,0.015087,0.015087,0.015087,0.43752,0.64874,0.64874
14 | 2,0.4466,1.4887,2.1139,2.3223,1.4887,0.65501,0.029773,-1.0123,-1.4291,-1.4291,-1.0123,-1.2207,-1.6375,-1.6375,-1.2207,-0.59546,-0.17864,0.23818,0.23818,0.029773,-0.17864,0.23818,0.23818,0.029773,0.029773,0.23818,0.23818,0.65501,0.86342,1.0718,0.86342,0.4466,0.23818,0.23818,0.23818,0.23818,0.23818,0.4466,0.86342,0.4466,1.0718,1.9055,1.6971,1.9055,1.0718,0.029773,-1.0123,-1.6375,-1.8459,-1.2207,-1.0123,-1.0123,-1.6375,-1.8459,-1.6375,-1.0123,-0.59546,-0.38705,-0.17864,-0.17864,0.029773,0.23818,0.4466,0.4466,0.23818,0.23818,0.23818,0.23818,0.029773,0.029773
15 | 2,0.16473,1.213,1.6323,2.0516,1.4227,0.58404,-0.25458,-0.88354,-1.3029,-1.0932,-0.67389,-1.0932,-1.5125,-1.5125,-1.3029,-0.67389,-0.044926,0.16473,0.16473,0.16473,-0.044926,-0.044926,0.16473,0.16473,0.16473,0.58404,1.0033,1.0033,1.0033,0.79369,0.58404,0.37438,0.37438,0.37438,0.58404,0.58404,0.58404,0.58404,0.79369,0.16473,1.213,1.842,2.2613,1.842,0.79369,-0.044926,-0.88354,-1.7222,-1.5125,-1.5125,-1.0932,-0.88354,-1.5125,-1.9318,-1.9318,-1.7222,-0.88354,-0.67389,-0.46424,-0.25458,-0.044926,0.16473,0.37438,0.37438,0.37438,0.16473,0.37438,0.16473,0.16473,-0.044926
16 | 2,-0.54621,0.17069,0.64863,1.3655,1.1266,0.40966,-0.30724,-0.78518,-0.78518,-0.54621,-0.30724,-0.30724,-0.78518,-1.2631,-1.5021,-1.0241,-0.54621,0.17069,0.40966,0.40966,0.17069,0.17069,0.17069,0.40966,0.40966,0.40966,0.40966,0.64863,0.8876,0.8876,0.8876,1.1266,0.64863,0.64863,0.40966,0.64863,0.64863,0.40966,0.64863,0.64863,0.64863,1.6045,1.8435,2.0824,2.3214,1.3655,0.17069,-1.0241,-1.98,-2.458,-2.219,-1.7411,-1.5021,-1.7411,-1.7411,-1.2631,-1.0241,-0.78518,-0.54621,-0.30724,-0.068277,0.17069,0.17069,0.17069,0.17069,0.40966,0.17069,-0.068277,-0.068277,-0.068277
17 | 1,-0.70754,-0.068472,0.5706,1.5292,2.1683,0.25106,-0.38801,-0.068472,-0.068472,-0.70754,-0.38801,-0.38801,-0.068472,-0.38801,-0.70754,-1.3466,-1.3466,-1.3466,-0.70754,-0.38801,-0.38801,-0.068472,0.25106,0.5706,0.25106,0.25106,0.25106,0.25106,-0.068472,0.25106,0.25106,0.5706,0.5706,0.5706,0.25106,0.25106,-0.068472,0.25106,-0.068472,0.89014,1.5292,2.1683,2.1683,2.1683,2.1683,0.5706,-1.0271,-1.0271,-1.3466,-1.0271,-1.0271,-1.6662,-1.6662,-2.3052,-2.6248,-1.6662,-0.068472,0.25106,-0.38801,-0.068472,0.25106,0.5706,0.5706,0.5706,0.25106,0.5706,0.5706,0.5706,0.25106,0.25106
18 | 2,0.16467,1.3174,1.0868,0.62574,0.16467,-0.065868,-0.2964,-0.2964,-0.065868,0.16467,-0.2964,-0.98801,-1.4491,-1.6796,-1.4491,-0.52694,0.16467,0.16467,-0.065868,0.16467,0.16467,0.85628,0.85628,0.39521,0.16467,0.16467,0.16467,0.39521,0.85628,0.85628,0.85628,0.62574,0.62574,0.85628,0.85628,0.62574,0.62574,0.39521,0.62574,0.62574,1.5479,1.7784,1.7784,2.2395,1.3174,0.16467,-0.75748,-1.4491,-1.4491,-0.98801,-0.75748,-1.4491,-2.1407,-2.6018,-2.3712,-1.9102,-1.4491,-0.75748,-0.75748,-0.2964,-0.065868,0.39521,0.62574,0.62574,0.16467,0.16467,0.16467,-0.065868,-0.065868,-0.065868
19 | 1,-0.84621,0.094024,1.0343,1.9745,1.5044,1.0343,0.094024,-1.0813,-1.0813,-0.3761,-0.61116,-1.0813,-2.2566,-2.7267,-1.7865,-0.3761,0.32908,0.7992,0.56414,0.094024,-0.3761,-0.14104,-0.14104,0.094024,0.094024,0.094024,0.094024,0.094024,0.32908,0.56414,0.56414,0.56414,0.56414,0.32908,0.32908,0.56414,0.32908,0.56414,0.7992,0.7992,0.32908,-0.3761,-0.14104,1.5044,1.9745,1.2693,0.56414,-0.3761,-1.0813,-0.61116,-0.14104,-0.3761,-1.0813,-2.0215,-2.7267,-2.4916,-1.0813,-0.3761,-0.14104,-0.14104,-0.14104,0.32908,0.32908,0.7992,0.7992,0.7992,0.7992,0.7992,0.7992,0.7992
20 | 2,1.2565,2.3457,2.3457,2.0734,1.2565,0.16727,-1.1942,-1.4665,-0.92193,-0.64963,-0.64963,-1.4665,-1.7388,-1.7388,-2.0111,-1.7388,-1.1942,-0.64963,-0.64963,-0.37733,-0.10503,0.43957,0.71187,0.71187,0.71187,0.43957,0.43957,0.16727,-0.10503,-0.37733,-0.37733,-0.37733,-0.10503,-0.37733,-0.10503,-0.10503,-0.37733,-0.10503,-0.37733,0.16727,0.71187,1.5288,2.0734,1.8011,0.71187,-0.10503,-0.64963,-0.64963,-0.37733,-0.37733,-0.10503,-0.64963,-1.1942,-1.7388,-1.1942,-0.37733,0.16727,0.71187,0.43957,0.43957,0.43957,0.43957,0.43957,0.16727,-0.10503,-0.10503,0.16727,0.71187,1.2565,1.5288
21 |
--------------------------------------------------------------------------------
/Signal-Alignment/data/TwoLeadECG_TRAIN:
--------------------------------------------------------------------------------
1 | 2,0.68835,0.61723,0.61723,0.56981,0.68835,0.64093,0.71205,0.78317,0.4987,0.47499,0.54611,0.33275,0.33275,0.26163,0.23793,0.26163,0.21422,0.21422,0.26163,0.23793,0.095692,0.1194,0.1194,-0.022839,0.16681,0.28534,0.16681,0.04828,0.16681,0.16681,0.1431,-0.80514,-2.1801,-3.0098,-3.0098,-2.8439,-2.9624,-2.5831,-2.0379,-2.0853,-1.8482,-1.4689,-1.2319,-1.137,-0.6629,-0.37843,-0.33102,-0.14137,0.28534,0.45128,0.4987,0.40387,0.33275,0.47499,0.28534,0.42758,0.4987,0.61723,0.54611,0.4987,0.54611,0.61723,0.66464,0.66464,0.71205,0.80688,0.78317,0.85429,0.80688,0.9017,0.85429,0.73576,0.71205,0.64093,0.56981,0.45128,0.40387,0.35646,0.21422,0.1431,0.16681,0.1431
2 | 1,-0.11165,-0.036505,-0.074079,-0.061555,0.038643,0.051168,0.13884,0.23904,0.21399,0.23904,0.063693,0.10127,0.063693,0.0010692,-0.036505,-0.074079,-0.16175,-0.12418,-0.1868,-0.1868,-0.32457,-0.24943,-0.22438,-0.27448,-0.31205,-0.287,-0.21185,-0.32457,-0.04903,0.36429,-0.04903,-0.85061,-1.8526,-2.5164,-2.7419,-2.792,-2.3786,-2.0655,-1.9778,-1.8651,-1.6647,-1.5771,-1.2765,-1.0385,-0.67527,-0.37467,-0.14923,0.076218,0.38934,0.57721,0.66488,0.67741,0.72751,0.76508,0.79013,0.86528,0.91538,0.96548,1.0406,1.0657,1.1408,1.216,1.2535,1.2911,1.3663,1.3537,1.3663,1.3287,1.3036,1.1784,1.0531,0.96548,0.80265,0.68993,0.55216,0.45196,0.36429,0.25156,0.13884,0.063693,0.0010692,-0.011456
3 | 2,-0.49172,-0.45549,-0.45549,-0.43738,-0.40115,-0.3287,-0.25624,-0.22001,-0.12945,-0.11133,-0.23813,-0.25624,-0.27435,-0.31058,-0.27435,-0.34681,-0.29247,-0.31058,-0.31058,-0.3287,-0.36492,-0.34681,-0.36492,-0.34681,-0.31058,-0.31058,-0.3287,-0.36492,-0.31058,-0.14756,-0.29247,-1.0351,-2.2125,-2.6835,-2.6472,-2.611,-2.3393,-1.814,-1.651,-1.488,-1.2525,-1.017,-0.79965,-0.4736,-0.22001,-0.038878,0.087917,0.28717,0.52264,0.68567,0.74001,0.77623,0.84869,0.8668,0.95737,0.97548,0.9936,1.0842,1.1385,1.211,1.2834,1.3378,1.374,1.4283,1.4464,1.4827,1.4102,1.3196,1.2653,1.1385,0.9936,0.92114,0.83057,0.74001,0.63133,0.55887,0.50453,0.4683,0.45019,0.39585,0.41396,0.43208
4 | 1,-0.3477,-0.24788,-0.28531,-0.2354,-0.18549,-0.11063,-0.073193,0.089018,0.12645,0.089018,0.014152,-0.035759,-0.098148,-0.11063,-0.21045,-0.24788,-0.31027,-0.28531,-0.32275,-0.39761,-0.44753,-0.41009,-0.41009,-0.38514,-0.39761,-0.42257,-0.43505,-0.3477,-0.098148,-0.1231,-0.85929,-1.7203,-2.1819,-2.3441,-2.4939,-2.3317,-1.9199,-1.7702,-1.7702,-1.6703,-1.6204,-1.3834,-1.1088,-0.77195,-0.44753,-0.29779,-0.048237,0.25123,0.52574,0.68795,0.72538,0.76282,0.82521,0.87512,0.92503,0.96246,1.0623,1.0997,1.1621,1.2619,1.2869,1.3617,1.3742,1.4241,1.499,1.4865,1.4117,1.3742,1.2619,1.1496,1.1122,0.96246,0.81273,0.68795,0.58813,0.47583,0.42592,0.35105,0.31362,0.3261,0.28866,0.30114
5 | 1,0.015379,0.0406,0.0027682,-0.0098423,0.0027682,-0.0098423,0.11626,0.078431,0.21715,0.25498,0.24237,0.26759,0.29281,0.20454,0.14148,0.091042,0.0406,-0.085505,-0.035063,-0.060284,-0.060284,-0.12334,-0.26205,-0.22422,-0.22422,-0.21161,-0.199,-0.28727,-0.23683,-0.17378,-0.3251,0.05321,0.39369,-0.047674,-1.0061,-2.0023,-2.5445,-2.7841,-2.822,-2.4184,-2.1158,-1.9771,-1.8384,-1.7501,-1.6366,-1.2961,-1.0313,-0.71603,-0.33771,-0.199,0.078431,0.2802,0.48197,0.57024,0.59546,0.62068,0.65851,0.68373,0.72157,0.77201,0.82245,0.87289,0.93594,0.98639,1.062,1.1377,1.1629,1.226,1.2764,1.3269,1.3016,1.3143,1.2764,1.1882,1.0747,0.98639,0.84767,0.69634,0.58285,0.46936,0.33064,0.25498
6 | 1,-0.34443,-0.32979,-0.32979,-0.32979,-0.37371,-0.35907,-0.35907,-0.21266,-0.15409,-0.11017,0.050887,0.065528,0.050887,0.036246,-0.051601,-0.12481,-0.15409,-0.24194,-0.25658,-0.28586,-0.3005,-0.40299,-0.41763,-0.46156,-0.44692,-0.43227,-0.46156,-0.46156,-0.41763,-0.44692,-0.43227,-0.022319,0.16802,-0.59333,-1.4132,-2.1453,-2.4088,-2.6577,-2.4235,-1.8964,-1.7207,-1.6475,-1.5304,-1.4279,-1.1497,-0.87151,-0.57869,-0.35907,-0.27122,0.021605,0.27051,0.46084,0.65118,0.66582,0.72438,0.76831,0.78295,0.8708,0.92936,0.98793,1.149,1.1343,1.2661,1.3393,1.3686,1.4711,1.515,1.5589,1.5589,1.5736,1.5004,1.3686,1.2661,1.1197,1.0026,0.88544,0.78295,0.68046,0.56333,0.49012,0.37299,0.34371
7 | 2,0.22125,0.24137,0.30171,0.34194,0.42239,0.48273,0.50285,0.36205,0.32182,0.28159,0.22125,0.22125,0.18102,0.12068,0.12068,0.12068,0.10057,0.040228,0.020114,0.020114,-0.020114,-0.040228,-0.040228,-0.060342,-0.020114,-0.080455,-0.12068,0.040228,-0.080455,-1.0057,-2.293,-3.0372,-3.0372,-3.0372,-2.7556,-2.1522,-1.9108,-1.6896,-1.4281,-1.2269,-0.94535,-0.66376,-0.36205,-0.1408,-0.060342,0.10057,0.38216,0.60342,0.68387,0.70398,0.74421,0.76433,0.80455,0.80455,0.84478,0.90512,0.92524,0.98558,1.0861,1.1264,1.1867,1.2471,1.2471,1.2471,1.1867,1.1063,0.98558,0.90512,0.70398,0.56319,0.46262,0.36205,0.20114,0.10057,-5.0608e-010,-0.040228,-0.16091,-0.20114,-0.22125,-0.24137,-0.28159,-0.30171
8 | 2,-0.56844,-0.53012,-0.51097,-0.47265,-0.39602,-0.30022,-0.24275,-0.24275,-0.20443,-0.28107,-0.28107,-0.31938,-0.37686,-0.33854,-0.3577,-0.31938,-0.22359,-0.28107,-0.26191,-0.3577,-0.28107,-0.30022,-0.24275,-0.30022,-0.22359,-0.24275,-0.33854,-0.20443,-0.20443,-0.089483,-0.20443,-0.56844,-1.5072,-2.3885,-2.6567,-2.5417,-2.3502,-2.0819,-1.7946,-1.7946,-1.4689,-1.239,-1.0857,-0.76002,-0.60676,-0.26191,-0.051167,0.025467,0.40863,0.5619,0.81096,0.86843,0.84927,0.83012,0.86843,0.88759,0.92591,0.92591,1.0025,0.98338,1.0217,1.0983,1.1366,1.1366,1.2133,1.2516,1.3091,1.3474,1.3091,1.3474,1.3282,1.2133,1.2324,1.175,0.96422,0.92591,0.7918,0.73432,0.65769,0.52358,0.52358,0.46611
9 | 1,0.059847,0.084142,0.16917,0.24206,0.2785,0.42426,0.35138,0.32709,0.33923,0.21776,0.13273,0.20561,0.16917,0.13273,0.059847,0.0477,-0.00088882,-0.061625,-0.12236,-0.11021,-0.13451,-0.1831,-0.1831,-0.098066,-0.23169,-0.23169,-0.23169,0.071994,0.18132,-0.75402,-1.9201,-2.5397,-2.7097,-2.8676,-2.7947,-2.321,-2.0659,-1.8959,-1.7501,-1.6286,-1.4221,-1.0941,-0.76616,-0.40175,-0.24383,0.023406,0.20561,0.39997,0.54574,0.58218,0.58218,0.63077,0.7158,0.6915,0.6915,0.75224,0.81297,0.86156,0.9223,0.94659,1.0195,1.0559,1.1045,1.1652,1.226,1.1895,1.2017,1.1895,1.1531,1.0438,0.93445,0.83727,0.72794,0.63077,0.52144,0.38782,0.2785,0.19347,0.096289,0.023406,-0.025183,-0.049478
10 | 1,0.94789,-0.021175,-0.021175,-0.021175,-0.021175,-0.033165,-0.021175,0.0028032,0.074739,0.13469,0.17065,0.30254,0.19463,0.15866,0.14668,0.086728,-0.0091861,0.014793,-0.033165,-0.081122,-0.1051,-0.12908,-0.16505,-0.22499,-0.28494,-0.27295,-0.28494,-0.27295,-0.28494,-0.29693,-0.30892,-0.34489,-0.15306,0.038771,-0.3329,-1.364,-2.1673,-2.407,-2.455,-2.467,-2.2512,-1.9874,-1.8915,-1.8316,-1.7237,-1.6277,-1.34,-1.1002,-0.78849,-0.50075,-0.29693,0.0028032,0.31453,0.57829,0.63824,0.6742,0.72216,0.77012,0.81808,0.85404,0.87802,0.92598,0.99792,1.0459,1.1298,1.1897,1.2497,1.3096,1.3696,1.3576,1.4056,1.3696,1.3576,1.2617,1.1418,1.0219,0.87802,0.72216,0.61426,0.47039,0.35049,0.2306
11 | 1,-0.059018,-0.059018,-0.070513,-0.024532,0.032943,0.10191,0.1249,0.25135,0.26285,0.19388,0.15939,0.1249,0.032943,0.044439,-0.047523,-0.059018,-0.093503,-0.12799,-0.17397,-0.20846,-0.25444,-0.25444,-0.24294,-0.25444,-0.27743,-0.28892,-0.28892,-0.27743,-0.27743,0.032943,0.021448,-0.8177,-1.7373,-2.3351,-2.5305,-2.5994,-2.519,-2.1856,-1.9902,-1.9097,-1.7718,-1.6683,-1.4384,-1.1396,-0.84069,-0.53032,-0.32341,-0.093503,0.19388,0.44677,0.63069,0.73415,0.76863,0.74564,0.79162,0.83761,0.89508,0.91807,0.96405,1.0215,1.1135,1.1825,1.2055,1.2514,1.3089,1.3089,1.3434,1.3434,1.3204,1.2399,1.171,1.0675,0.91807,0.81461,0.66518,0.58471,0.48125,0.35481,0.27434,0.25135,0.1479,0.090419
12 | 2,0.10939,0.090422,0.090422,0.14731,0.2042,0.26109,0.31798,0.35591,0.2042,0.18524,0.18524,0.090422,0.071459,0.052496,-0.0043939,0.014569,0.014569,-0.0043939,-0.04232,-0.09921,-0.11817,-0.11817,-0.13714,-0.11817,-0.1561,-0.1561,-0.21299,-0.11817,0.014569,-0.45951,-1.4456,-2.6403,-3.1144,-3.1144,-3.0195,-2.6024,-1.9386,-1.7869,-1.5214,-1.1801,-1.0094,-0.70603,-0.44055,-0.23195,-0.023357,0.090422,0.29902,0.54554,0.73517,0.7731,0.7731,0.79206,0.84895,0.86791,0.88688,0.9248,1.0007,1.0386,1.0765,1.1334,1.1713,1.2093,1.2472,1.2472,1.2282,1.1713,1.0575,0.94377,0.86791,0.73517,0.58347,0.46969,0.33694,0.24213,0.14731,0.052496,0.014569,-0.080247,-0.11817,-0.04232,-0.061283,-0.09921
13 | 1,0.12417,0.11144,0.14962,0.13689,0.12417,0.13689,0.1878,0.21326,0.25144,0.35326,0.42962,0.34053,0.35326,0.3278,0.1878,0.20053,0.098713,0.060532,0.035077,-0.028558,-0.015831,-0.092194,-0.18128,-0.18128,-0.19401,-0.20674,-0.21947,-0.21947,-0.24492,-0.27037,-0.2831,-0.054013,0.28962,-0.20674,-1.3395,-2.2813,-2.5994,-2.6631,-2.6504,-2.3067,-2.0522,-1.9631,-1.8358,-1.7467,-1.6449,-1.3395,-1.034,-0.71582,-0.47401,-0.25765,-0.0031042,0.27689,0.54416,0.65871,0.70962,0.73507,0.77325,0.82416,0.86234,0.87507,0.95143,1.066,1.0914,1.1423,1.206,1.2442,1.2696,1.2823,1.3078,1.3078,1.2696,1.1678,1.066,0.92598,0.78598,0.64598,0.53144,0.36598,0.23871,0.14962,-0.015831,-0.06674
14 | 1,0.21032,0.21032,0.19821,0.19821,0.24666,0.25877,0.36777,0.39199,0.45255,0.46466,0.34355,0.28299,0.16188,0.077099,0.12554,0.11343,0.10132,0.10132,0.064987,0.004431,-0.080348,-0.10457,-0.11668,-0.11668,-0.1409,-0.15302,-0.1409,-0.16513,-0.17724,-0.21357,-0.0076803,0.24666,-0.24991,-1.2915,-2.115,-2.4905,-2.6722,-2.7448,-2.442,-2.115,-2.006,-1.9576,-1.8486,-1.7638,-1.461,-1.1583,-0.79491,-0.54058,-0.38313,-0.10457,0.25877,0.53733,0.62211,0.64633,0.64633,0.68266,0.68266,0.719,0.74322,0.79166,0.85222,0.87644,0.937,0.99756,1.0218,1.0823,1.1308,1.155,1.2034,1.2034,1.2156,1.2034,1.1308,1.0581,0.937,0.79166,0.64633,0.47677,0.39199,0.21032,0.08921,-0.0076803
15 | 1,-0.04372,0.0037639,0.039377,0.1106,0.18183,0.30054,0.24118,0.20557,0.16996,0.074989,0.063118,0.015635,-0.031849,-0.067461,-0.079332,-0.091203,-0.15056,-0.22178,-0.24552,-0.2574,-0.2574,-0.24552,-0.23365,-0.24552,-0.28114,-0.2574,-0.2574,0.039377,0.098731,-0.70849,-1.7769,-2.3585,-2.5366,-2.5841,-2.4298,-2.0974,-1.9905,-1.9193,-1.8125,-1.765,-1.5869,-1.2545,-0.87468,-0.57791,-0.3761,-0.15056,0.18183,0.46673,0.57357,0.66853,0.69227,0.69227,0.73976,0.7635,0.81098,0.8466,0.88221,0.95343,1.0009,1.0484,1.1078,1.1671,1.2383,1.2739,1.2858,1.3333,1.357,1.3333,1.2739,1.1909,1.0603,0.95343,0.81098,0.69227,0.57357,0.44299,0.33615,0.21744,0.14621,0.08686,0.027506,-0.0081069
16 | 2,0.023235,0.0039899,0.023235,0.061726,0.11946,0.1772,0.23494,0.27343,0.15795,0.11946,0.10022,0.0039899,-0.015256,-0.015256,-0.053747,0.0039899,-0.053747,-0.053747,-0.092237,-0.13073,-0.14997,-0.13073,-0.14997,-0.14997,-0.14997,-0.14997,-0.18846,-0.13073,-0.015256,-0.47715,-1.6511,-2.8636,-2.9791,-2.9213,-2.7866,-2.3824,-1.959,-1.8243,-1.5741,-1.2855,-1.0738,-0.70809,-0.41941,-0.18846,0.0039899,0.15795,0.33116,0.6006,0.75456,0.8123,0.83155,0.85079,0.88928,0.92777,0.92777,0.98551,1.0432,1.101,1.1395,1.178,1.2549,1.2934,1.2742,1.2934,1.2742,1.2165,1.0817,0.98551,0.83155,0.69683,0.58135,0.48513,0.35041,0.25418,0.15795,0.080972,0.042481,-0.015256,-0.072992,-0.053747,-0.053747,-0.072992
17 | 1,0.13847,0.18783,0.15081,0.2372,0.28656,0.39764,0.47169,0.39764,0.34827,0.33593,0.24954,0.31125,0.20017,0.10144,0.064417,0.064417,0.0027091,-0.034316,-0.096023,-0.10836,-0.15773,-0.14539,-0.14539,-0.15773,-0.17007,-0.096023,-0.24412,-0.10836,0.33593,0.13847,-0.76247,-1.7375,-2.4903,-2.8112,-2.9346,-2.7371,-2.3052,-2.1324,-1.9102,-1.7375,-1.6017,-1.3425,-1.1451,-0.73778,-0.51564,-0.21944,-0.021974,0.22486,0.54574,0.5334,0.5951,0.70618,0.71852,0.70618,0.81725,0.73086,0.86662,0.85428,0.96535,0.97769,1.0517,1.1628,1.1011,1.1875,1.2369,1.2369,1.1752,1.2122,1.0641,0.99003,0.90364,0.78023,0.61979,0.47169,0.42232,0.32359,0.20017,0.015051,0.039734,0.0027091,-0.13305,-0.12071
18 | 2,0.37854,0.37854,0.40218,0.42582,0.44946,0.54403,0.56767,0.66223,0.56767,0.40218,0.44946,0.37854,0.30762,0.28398,0.21306,0.30762,0.28398,0.18941,0.18941,0.11849,0.094851,0.04757,0.04757,0.04757,0.023929,-0.046993,-0.023352,-0.070634,-0.070634,0.04757,-0.070634,-0.85078,-2.1037,-2.9785,-3.0257,-2.8366,-2.5766,-2.3874,-2.2219,-1.9855,-1.7018,-1.4654,-1.2527,-0.89806,-0.63801,-0.37796,-0.23612,-0.023352,0.26034,0.4731,0.66223,0.70951,0.63859,0.68587,0.66223,0.73315,0.70951,0.70951,0.78043,0.85136,0.875,0.89864,0.92228,1.0168,1.0168,1.0405,1.0641,1.0405,1.0168,0.94592,0.82772,0.73315,0.59131,0.42582,0.3549,0.21306,0.094851,-0.046993,-0.11792,-0.1652,-0.2834,-0.30704
19 | 2,-0.13885,-0.11908,-0.059783,-0.020249,0.039052,0.019285,-0.00048212,-0.11908,-0.099317,-0.13885,-0.23769,-0.19815,-0.21792,-0.19815,-0.17839,-0.19815,-0.21792,-0.27722,-0.29699,-0.25745,-0.25745,-0.25745,-0.29699,-0.23769,-0.23769,-0.27722,-0.19815,-0.13885,-0.39582,-1.147,-2.2539,-2.7481,-2.7876,-2.5307,-2.333,-2.0365,-1.9179,-1.7202,-1.4435,-1.2458,-0.96907,-0.65279,-0.43536,-0.21792,-0.040016,0.21695,0.45416,0.71113,0.7902,0.7902,0.7902,0.82973,0.86927,0.82973,0.8495,0.9681,0.98787,1.0472,1.1065,1.146,1.2053,1.2844,1.3634,1.403,1.4227,1.3634,1.3239,1.2448,1.1658,1.0274,0.88903,0.80996,0.6716,0.53323,0.39486,0.33556,0.27626,0.11812,0.19719,0.11812,0.078586,0.078586
20 | 1,0.12505,0.11151,0.11151,0.016685,0.07087,0.097962,0.12505,0.084416,0.17924,0.28761,0.36889,0.27406,0.24697,0.23342,0.19279,0.043777,-0.11878,0.016685,0.084416,-0.13232,-0.29488,-0.28133,-0.28133,-0.44389,-0.3897,-0.40325,-0.40325,-0.36261,-0.45743,-0.48453,-0.36261,0.043777,-0.18651,-1.1754,-1.934,-2.2726,-2.4081,-2.5029,-2.3268,-2.0017,-1.934,-1.8391,-1.7308,-1.6901,-1.3921,-1.1483,-0.85027,-0.52516,-0.41679,-0.010407,0.27406,0.45016,0.53144,0.57208,0.61272,0.70754,0.73463,0.78882,0.8701,0.93783,1.0056,1.1546,1.1952,1.1952,1.2629,1.4119,1.4119,1.439,1.3713,1.4661,1.3713,1.2223,1.1546,1.0327,0.88364,0.76173,0.57208,0.53144,0.43662,0.35534,0.19279,0.1386
21 | 2,0.17877,0.15846,0.15846,0.21937,0.25998,0.28028,0.32089,0.23968,0.19907,0.17877,0.097554,0.056948,0.097554,0.016342,0.036645,-0.0039616,-0.0039616,-0.0039616,-0.064871,-0.10548,-0.064871,-0.064871,-0.10548,-0.085174,-0.10548,-0.14608,-0.14608,-0.024265,0.016342,-0.53185,-1.6282,-2.7043,-3.1104,-2.9479,-2.8261,-2.6637,-2.0749,-1.8516,-1.547,-1.3034,-1.1003,-0.77548,-0.53185,-0.30851,-0.12578,-0.0039616,0.23968,0.44271,0.64574,0.68635,0.68635,0.74726,0.74726,0.78786,0.76756,0.80817,0.90968,0.92999,0.92999,1.0315,1.0924,1.1127,1.1736,1.1939,1.2345,1.2345,1.1736,1.1127,1.0112,0.88938,0.78786,0.68635,0.54423,0.4021,0.28028,0.19907,0.13816,0.056948,-0.0039616,-0.024265,-0.044568,-0.16639
22 | 2,1.8705,0.085998,0.10925,0.1325,0.10925,0.1325,0.1325,0.20227,0.17901,0.24877,0.27203,0.34179,0.31853,0.17901,0.15576,0.085998,0.085998,0.062744,-0.030269,0.062744,0.039491,-0.0070159,0.016238,-0.030269,-0.076776,-0.030269,-0.14654,-0.053523,-0.030269,-0.14654,-0.12328,-0.12328,-0.076776,0.062744,-0.28606,-1.1232,-2.2626,-2.9137,-2.9602,-2.7044,-2.5649,-2.2859,-2.1231,-1.8673,-1.4952,-1.286,-1.1232,-0.82089,-0.5651,-0.33256,-0.2163,0.039491,0.36504,0.52781,0.59757,0.62083,0.59757,0.62083,0.62083,0.64408,0.69059,0.73709,0.7836,0.85336,0.89987,0.94638,1.0161,1.1091,1.1557,1.1557,1.1557,1.1324,1.1324,1.0394,0.94638,0.83011,0.71384,0.62083,0.50456,0.38829,0.29528,0.17901
23 | 2,0.24911,0.21049,0.2298,0.2298,0.19119,0.21049,0.24911,0.26841,0.32633,0.34564,0.40356,0.44218,0.30703,0.30703,0.30703,0.21049,0.15257,0.15257,0.11396,0.13326,0.094651,0.11396,0.03673,-0.040497,-0.059804,-0.059804,-0.079111,-0.13703,-0.17565,-0.21426,-0.19495,-0.13703,-0.11773,-0.6004,-1.6237,-2.7628,-3.1489,-3.1103,-2.9752,-2.6083,-2.0677,-1.894,-1.6044,-1.2954,-1.1603,-0.77416,-0.46525,-0.23357,-0.098418,0.075344,0.28772,0.5001,0.57732,0.59663,0.63525,0.65455,0.65455,0.67386,0.73178,0.77039,0.80901,0.88624,0.94416,1.0021,1.0021,1.0986,1.1565,1.1372,1.1179,1.1372,1.0793,1.0021,0.86693,0.77039,0.67386,0.53871,0.40356,0.30703,0.21049,0.094651,0.017423,-0.059804
24 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/__pycache__/dbd_cf.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/__pycache__/dbd_cf.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/cf.py:
--------------------------------------------------------------------------------
1 | # warp_width is the parameter of sigmoid 1 / (1 + math.exp(-x/a))
2 | vertical_mov = -3
3 | height_of_gaussian = 1.2
4 | ds_time = 3
5 | anchor_shift = 10
6 | refer_percent = 0.1
7 | query_percent = 0.5
8 | min_product = 10
--------------------------------------------------------------------------------
/Signal-Alignment/debug/dbd_cf.py:
--------------------------------------------------------------------------------
1 | debug_file = '../data/ECGFiveDays_TRAIN'
2 | debug_line = 5
3 |
4 | font_xlabel = {
5 | 'family': 'Arial',
6 | 'weight': 'normal',
7 | 'size': 35
8 | }
--------------------------------------------------------------------------------
/Signal-Alignment/debug/dowmsample_ddtw_dbg.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | from parameter_cal import cf
4 | from dtw import dtw
5 | from downsample.utils import get_true_aligned, get_group_number
6 | from parameter_cal.utils import get_SS2, get_group_devi, get_SS1, get_fact_align, get_reverse_dict, get_link_graph
7 | from parameter_cal.utils import load_data, plot_warped_signals, cal_warped_signals
8 | from downsample.utils import slope_col, reference_slope_col, get_k_accuracy
9 | from debug.dbd_cf import debug_file, debug_line
10 |
11 |
12 | def norm(x, y):
13 | return math.fabs(x[1] - y[1])
14 |
15 |
16 | # generate warped signal
17 | y_list = load_data(debug_file, debug_line)
18 | y_list = y_list[:-(len(y_list)%cf.ds_time)]
19 | query, reference = cal_warped_signals(y_list, 'right')
20 |
21 | # plot warped signal
22 | # downsample times
23 | xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
24 | query2 = pd.DataFrame({'t':xvals, 'q':yinterp})
25 |
26 |
27 | # calculate the corresponding point pair
28 | query.drop(['shift','t'], axis=1)
29 | query2['close_index'] = 0
30 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
31 | group_num_dict = get_group_number(true_align_dict, query)
32 |
33 |
34 | reference_slope_col(reference, cf.ds_time)
35 | slope_col(query2)
36 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'avg_slope']].values, query2[['t', 'slope']].values, dist=norm)
37 | get_link_graph(reference, query2, path, -3, 'Downsampled signal with dDTW', '(b) dDTW')
38 | fact_align_dict = get_fact_align(path)
39 | reverse_dict = get_reverse_dict(path)
40 | print("path = "+ str(len(path[0])))
41 | print('group = '+str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
42 | print("SS1 of ddtw is "+ str(get_SS1(fact_align_dict, cf.ds_time)))
43 | print("SS2 of ddtw is " + str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample/__pycache__/utils.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/downsample/__pycache__/utils.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample/__pycache__/utils.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/downsample/__pycache__/utils.cpython-38.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample/utils.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import math
3 | from parameter_cal.utils import get_group_devi, get_SS1, get_SS2
4 | from parameter_cal import cf
5 | import pandas as pd
6 | import matplotlib.pyplot as plt
7 |
8 |
9 | def get_group_len(query_st, query2_checkpoint, ds_time, query, query2):
10 | group_len = 0
11 | for i in range(0, ds_time):
12 | group_len += math.sqrt(pow((query2['t'][query2_checkpoint] - query['t2'][i + query_st]), 2) + pow(
13 | (query2['q'][query2_checkpoint] - query['q'][i + query_st]), 2))
14 | return group_len
15 |
16 |
17 | def get_true_aligned(ds_time, query, query2):
18 | if math.floor(ds_time) == math.ceil(ds_time):
19 | ds_time = int(ds_time)
20 | dict = {}.fromkeys(range(0, len(query2['t'])))
21 | for i in range(len(query2['t'])):
22 | dict[i] = np.array([])
23 | # find the closest index
24 | for i in range(len(query2)):
25 | for j in range(len(query['t']) - 1):
26 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
27 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
28 | query2.loc[i, 'close_index'] = j
29 | dict[i] = np.append(dict[i], j)
30 | else:
31 | query2.loc[i, 'close_index'] = j + 1
32 | dict[i] = np.append(dict[i], j + 1)
33 | if query2['t'][i] > query['t2'].iloc[-1]:
34 | query2.loc[i, 'close_index'] = len(query) - 1
35 | elif query2['t'][i] < query['t2'].iloc[0]:
36 | query2.loc[i, 'close_index'] = 0
37 | dict[len(query2['t']) - 1] = np.array([len(query) - 1])
38 | for i in range(len(query2['t'])):
39 | min_len = np.inf
40 | center = int(dict[i][0])
41 | for j in range(-ds_time + 1, 1):
42 | st, ed = center + j, center + j + ds_time - 1
43 | if st < 0 or ed >= len(query['t2']):
44 | continue
45 | # print(i, st, center, j)
46 | group_len = get_group_len(st, i, ds_time, query, query2)
47 | if group_len < min_len:
48 | dict[i] = np.array(list(range(center + j, center + j + ds_time)))
49 | min_len = group_len
50 | return dict
51 | # find the rest closest ones
52 |
53 |
54 | def get_group_number(true_align_dict, query):
55 | diction = {}.fromkeys(range(0, len(query['q'])))
56 | for i in range(len(query['q'])):
57 | diction[i] = np.array([])
58 | diction = {}.fromkeys(range(0, len(query['q'])))
59 | for i in range(len(query['q'])):
60 | diction[i] = np.array([])
61 | for i in range(len(true_align_dict)):
62 | for item in true_align_dict[i]:
63 | diction[item] = np.append(diction[item], i)
64 | # modify those that did not find their group
65 | for i in range(len(diction)):
66 | if len(diction[i]) == 0:
67 | diction[i] = np.append(diction[i], diction[i - 1][0])
68 | return diction
69 |
70 |
71 | def get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict):
72 | sum = 0
73 | consider_num = 0
74 | query_number = len(fact_align_dict)
75 | for i in range(len(fact_align_dict)):
76 | for item in fact_align_dict[i]:
77 | consider_num += 1
78 | if item in true_align_dict[i]:
79 | sum += 0
80 | else:
81 | # search the group number
82 | group_devi = get_group_devi(item, group_num_dict, i)
83 | sum += group_devi
84 | # sum+=min(np.abs(item-true_align_dict[i]))
85 | return 2 * sum / ((query_number * (query_number - 1)) * (1 + math.fabs(cf.ds_time)))
86 |
87 |
88 | def slope_col(query):
89 | # calculate the slope of query
90 | query_last = len(query) - 1
91 | query['slope'] = 0
92 | query.loc[1, 'slope'] = ((query.loc[1, 'q'] - query.loc[0, 'q']) + (
93 | (query.loc[2, 'q'] - query.loc[1, 'q']) / 2)) / 2
94 | query.loc[0, 'slope'] = query.loc[1, 'slope']
95 | for i in range(2, query_last - 1):
96 | query.loc[i, 'slope'] = ((query.loc[i, 'q'] - query.loc[i - 1, 'q']) + (
97 | (query.loc[i + 1, 'q'] - query.loc[i, 'q']) / 2)) / 2
98 | query.loc[query_last - 1, 'slope'] = ((query.loc[query_last - 1, 'q'] - query.loc[query_last - 2, 'q']) + (
99 | (query.loc[query_last, 'q'] - query.loc[query_last - 1, 'q']) / 2)) / 2
100 | query.loc[query_last, 'slope'] = query.loc[query_last - 1, 'slope']
101 |
102 |
103 | def reference_slope_col(query, ds_time):
104 | slope_col(query)
105 | query['avg_slope'] = 0
106 | left_right = ds_time
107 | st = 0 + left_right
108 | ed = len(query) - 1 - left_right
109 | for i in range(0, ed + 1):
110 | query.loc[i, 'avg_slope'] = (query.loc[i + left_right, 'q'] - query.loc[i, 'q']) / 2
111 | for i in range(ed + 1, len(query) - 1):
112 | query.loc[i, 'avg_slope'] = query.loc[i, 'slope']
113 |
114 |
115 | def get_warped_signals(query, ds_time):
116 | if ds_time == 1:
117 | xvals = query['t']
118 | xvals = np.array(xvals)
119 | else:
120 | xvals = np.linspace(query.loc[0, 't2'], query.iloc[-1]['t2'], math.floor(len(query['t']) / cf.ds_time))
121 | x = query['t2']
122 | y = query['q']
123 | yinterp = np.array(np.interp(xvals, x, y))
124 | return xvals, yinterp
125 |
126 |
127 | def connect_edges(reference_up_or_down_slope, connect_expansion):
128 | tempdf = pd.DataFrame(columns=reference_up_or_down_slope.columns)
129 | i = 0
130 | while 0 <= i < len(reference_up_or_down_slope):
131 | ed = reference_up_or_down_slope.loc[i, 'ed']
132 | j = i + 1
133 | while 0 <= j < len(reference_up_or_down_slope):
134 | if math.fabs(ed - reference_up_or_down_slope.loc[j, 'st']) <= connect_expansion:
135 | reference_up_or_down_slope.loc[i, 'ed'] = reference_up_or_down_slope.loc[j, 'ed']
136 | j += 1
137 | else:
138 | break
139 | tempdf.loc[len(tempdf), :] = reference_up_or_down_slope.loc[i, :]
140 | i = j
141 | return tempdf
142 |
143 |
144 | def get_matched_graph(rising_edge_grps, down_edge_grps, x, y, vertical_mov, title=None):
145 | plt.figure(figsize=(20, 10))
146 | plt.scatter(x['t'], x['q'], c='k', marker='.', label='reference')
147 | plt.scatter(y['t'], y['q'] + vertical_mov, c='b', marker='.', label='query')
148 | for i in range(0, len(rising_edge_grps)):
149 | refer_st = int(rising_edge_grps.iloc[i]['refer_st'])
150 | refer_ed = int(rising_edge_grps.iloc[i]['refer_ed'])
151 | query_st = int(rising_edge_grps.iloc[i]['query_st'])
152 | query_ed = int(rising_edge_grps.iloc[i]['query_ed'])
153 | plt.plot(x['t'].loc[refer_st:refer_ed], x['q'].loc[refer_st:refer_ed], color='r')
154 | plt.plot(y['t'].loc[query_st:query_ed], y['q'].loc[query_st:query_ed] + vertical_mov, color='r')
155 |
156 | for i in range(0, len(down_edge_grps)):
157 | refer_st = int(down_edge_grps.iloc[i]['refer_st'])
158 | refer_ed = int(down_edge_grps.iloc[i]['refer_ed'])
159 | query_st = int(down_edge_grps.iloc[i]['query_st'])
160 | query_ed = int(down_edge_grps.iloc[i]['query_ed'])
161 | plt.plot(x['t'].loc[refer_st:refer_ed], x['q'].loc[refer_st:refer_ed], color='orange')
162 | plt.plot(y['t'].loc[query_st:query_ed], y['q'].loc[query_st:query_ed] + vertical_mov, color='orange')
163 | plt.title(label=title, fontsize='30')
164 | plt.show()
165 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample_dtw_dbg.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import numpy as np
4 | from parameter_cal import cf
5 | from dtw import dtw
6 | from parameter_cal.utils import get_SS1, get_fact_align, get_reverse_dict, get_SS2, get_link_graph
7 | from parameter_cal.utils import load_data, plot_warped_signals, cal_warped_signals
8 | import matplotlib.pyplot as plt
9 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
10 | from debug.dbd_cf import debug_file, debug_line
11 |
12 |
13 | def norm(x, y):
14 | return math.fabs(x[1] - y[1])
15 |
16 |
17 | y_list = load_data(debug_file, debug_line)
18 | query, reference = cal_warped_signals(y_list, 'right')
19 |
20 | # plot warped signal
21 | # downsample times
22 | xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
23 |
24 | # calculate the corresponding point pair
25 | query.drop('shift', axis=1)
26 | query.drop('t', axis=1)
27 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
28 | query2['close_index'] = 0
29 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
30 | group_num_dict = get_group_number(true_align_dict, query)
31 |
32 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q']].values, query2[['t', 'q']].values, dist=norm)
33 | get_link_graph(reference, query2, path, -3, None, '(c) DTW')
34 | fact_align_dict = get_fact_align(path)
35 | reverse_dict = get_reverse_dict(path)
36 | print('group = '+str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
37 | print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
38 | print("SS2 of dtw is " + str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
39 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample_eventdtw_dbg.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import numpy as np
4 | from parameter_cal import cf
5 | from dtw import dtw
6 | from parameter_cal.utils import get_fact_align, get_SS1, get_SS2, get_reverse_dict, calculate_event, get_link_graph, load_data, exp_decay, edge_matching
7 | from parameter_cal.utils import plot_warped_signals, cal_warped_signals, get_upslope_endings, get_downslope_endings
8 | import matplotlib.pyplot as plt
9 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy, get_matched_graph, connect_edges
10 | from debug.dbd_cf import debug_file, debug_line
11 |
12 |
13 | def norm(x, y):
14 | #return math.fabs(x[1] - y[1])
15 | return math.fabs(x[1] - y[1])+math.fabs(x[2] - y[2])+math.fabs(x[3] - y[3])
16 |
17 | y_list = load_data(debug_file, debug_line)
18 | query, reference = cal_warped_signals(y_list, 'right')
19 |
20 | reference['upslope'] = 0
21 | reference['downslope'] = 0
22 |
23 | # plot warped signal
24 | xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
25 |
26 | # calculate the corresponding point pair
27 | query.drop('shift', axis=1)
28 | query.drop('t', axis=1)
29 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
30 | query2['close_index'] = 0
31 | query2['upslope'] = 0
32 | query2['downslope'] = 0
33 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
34 | group_num_dict = get_group_number(true_align_dict, query)
35 | plt.show()
36 |
37 | raw_reference_uslope, reference_upslope = get_upslope_endings(reference['q'], cf.refer_percent)
38 | raw_query_uslope, query_upslope = get_upslope_endings(query2['q'], cf.query_percent)
39 |
40 | raw_reference_downslope, reference_downslope = get_downslope_endings(reference['q'], cf.refer_percent)
41 | raw_query_downslope, query_downslope = get_downslope_endings(query2['q'], cf.query_percent)
42 |
43 | rising_edge_grps = edge_matching(reference, query2, reference_upslope, query_upslope)
44 | down_edge_grps = edge_matching(reference, query2, reference_downslope, query_downslope)
45 | rising_edge_grps = connect_edges(rising_edge_grps, raw_reference_uslope)
46 | get_matched_graph(rising_edge_grps, down_edge_grps, reference, query2, -3)
47 |
48 | calculate_event(rising_edge_grps, reference, query2, True)
49 | calculate_event(down_edge_grps, reference, query2, False)
50 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values,
51 | query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
52 | get_link_graph(reference, query2, path, -3, 'Downsampled signal with EventDTW', '(a) EventDTW')
53 | fact_align_dict = get_fact_align(path)
54 | reverse_dict = get_reverse_dict(path)
55 | print('group = ' + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
56 | print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
57 | print("SS2 of dtw is " + str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
58 |
59 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/downsample_shapedtw_dbg.py:
--------------------------------------------------------------------------------
1 | import math
2 | import numpy as np
3 | import pandas as pd
4 | from scipy import stats
5 | from scipy.misc import *
6 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
7 | from dtw import dtw
8 | from parameter_cal import cf
9 | from parameter_cal.cf import ds_time
10 | from parameter_cal.utils import cal_warped_signals, plot_warped_signals
11 | from parameter_cal.utils import get_fact_align, get_reverse_dict, get_SS2, get_SS1, get_link_graph, load_data
12 | from sdtw.config import sub_len, nBlocks
13 | from sdtw.utils import cal_descriptor, samplingSequences, norm
14 | from debug.dbd_cf import debug_line, debug_file
15 |
16 |
17 | # generate warped signal
18 | y_list = load_data(debug_file, debug_line)
19 | query, reference = cal_warped_signals(y_list, 'right')
20 |
21 | # plot warped signal
22 | # downsample times
23 | xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
24 |
25 |
26 | # normalize the signal
27 | reference_norm = stats.zscore(reference['q'])
28 | yinterp_norm = stats.zscore(yinterp)
29 |
30 | # store the corresponding point pair
31 | query.drop(['t','shift'], axis=1)
32 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
33 | query2['close_index'] = 0
34 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
35 | group_num_dict = get_group_number(true_align_dict, query)
36 |
37 | refer_subsequences = samplingSequences(reference_norm, sub_len)
38 | query_subsequences = samplingSequences(yinterp_norm, int(sub_len/cf.ds_time))
39 | refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
40 | query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
41 | refer_nsubsequences = len(refer_subsequences)
42 | query_nsubsequences = len(query_subsequences)
43 |
44 | for i in range(refer_nsubsequences):
45 | sub_seq = refer_subsequences[i]
46 | refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)
47 |
48 | for i in range(query_nsubsequences):
49 | sub_seq = query_subsequences[i]
50 | query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len/cf.ds_time))
51 |
52 | d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
53 | get_link_graph(reference, query2, path, -3, 'Downsampled signal with shapedtw','(d) shapeDTW')
54 | fact_align_dict = get_fact_align(path)
55 | reverse_dict = get_reverse_dict(path)
56 | print("error rate of shapedtw is " + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
57 | print("SS1 of shapedtw is " + str(get_SS1(path, cf.ds_time)))
58 | print("SS2 of shapedtw is " + str(get_SS2(fact_align_dict, reverse_dict, ds_time)))
59 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/dtw.py:
--------------------------------------------------------------------------------
1 | from numpy import array, zeros, full, argmin, inf, ndim
2 | from scipy.spatial.distance import cdist
3 | from math import isinf
4 |
5 | def dtw(x, y, dist, warp=1, w=inf, s=1.0):
6 | """
7 | Computes Dynamic Time Warping (DTW) of two sequences.
8 |
9 | :param array x: N1*M array
10 | :param array y: N2*M array
11 | :param func dist: distance used as cost measure
12 | :param int warp: how many shifts are computed.
13 | :param int w: window size limiting the maximal distance between indices of matched entries |i,j|.
14 | :param float s: weight applied on off-diagonal moves of the path. As s gets larger, the warping path is increasingly biased towards the diagonal
15 | Returns the minimum distance, the cost matrix, the accumulated cost matrix, and the wrap path.
16 | """
17 | assert len(x)
18 | assert len(y)
19 | assert isinf(w) or (w >= abs(len(x) - len(y)))
20 | assert s > 0
21 | r, c = len(x), len(y)
22 | if not isinf(w):
23 | D0 = full((r + 1, c + 1), inf)
24 | for i in range(1, r + 1):
25 | D0[i, max(1, i - w):min(c + 1, i + w + 1)] = 0
26 | D0[0, 0] = 0
27 | else:
28 | D0 = zeros((r + 1, c + 1))
29 | D0[0, 1:] = inf
30 | D0[1:, 0] = inf
31 | D1 = D0[1:, 1:] # view
32 | for i in range(r):
33 | for j in range(c):
34 | if (isinf(w) or (max(0, i - w) <= j <= min(c, i + w))):
35 | D1[i, j] = dist(x[i], y[j])
36 | C = D1.copy()
37 | jrange = range(c)
38 | for i in range(r):
39 | if not isinf(w):
40 | jrange = range(max(0, i - w), min(c, i + w + 1))
41 | for j in jrange:
42 | min_list = [D0[i, j]]
43 | for k in range(1, warp + 1):
44 | i_k = min(i + k, r)
45 | j_k = min(j + k, c)
46 | min_list += [D0[i_k, j] * s, D0[i, j_k] * s]
47 | D1[i, j] += min(min_list)
48 | if len(x) == 1:
49 | path = zeros(len(y)), range(len(y))
50 | elif len(y) == 1:
51 | path = range(len(x)), zeros(len(x))
52 | else:
53 | path = _traceback(D0)
54 | return D1[-1, -1] / sum(D1.shape), C, D1, path
55 | # return D1[-1, -1], C, D1, path
56 |
57 | def accelerated_dtw(x, y, dist, warp=1):
58 | """
59 | Computes Dynamic Time Warping (DTW) of two sequences in a faster way.
60 | Instead of iterating through each element and calculating each distance,
61 | this uses the cdist function from scipy (https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html)
62 |
63 | :param array x: N1*M array
64 | :param array y: N2*M array
65 | :param string or func dist: distance parameter for cdist. When string is given, cdist uses optimized functions for the distance metrics.
66 | If a string is passed, the distance function can be 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'wminkowski', 'yule'.
67 | :param int warp: how many shifts are computed.
68 | Returns the minimum distance, the cost matrix, the accumulated cost matrix, and the wrap path.
69 | """
70 | assert len(x)
71 | assert len(y)
72 | if ndim(x) == 1:
73 | x = x.reshape(-1, 1)
74 | if ndim(y) == 1:
75 | y = y.reshape(-1, 1)
76 | r, c = len(x), len(y)
77 | D0 = zeros((r + 1, c + 1))
78 | D0[0, 1:] = inf
79 | D0[1:, 0] = inf
80 | D1 = D0[1:, 1:]
81 | D0[1:, 1:] = cdist(x, y, dist)
82 | C = D1.copy()
83 | for i in range(r):
84 | for j in range(c):
85 | min_list = [D0[i, j]]
86 | for k in range(1, warp + 1):
87 | min_list += [D0[min(i + k, r), j],
88 | D0[i, min(j + k, c)]]
89 | D1[i, j] += min(min_list)
90 | if len(x) == 1:
91 | path = zeros(len(y)), range(len(y))
92 | elif len(y) == 1:
93 | path = range(len(x)), zeros(len(x))
94 | else:
95 | path = _traceback(D0)
96 | return D1[-1, -1] / sum(D1.shape), C, D1, path
97 |
98 |
99 | def _traceback(D):
100 | i, j = array(D.shape) - 2
101 | p, q = [i], [j]
102 | track_verti = 0
103 | track_hori = 0
104 | while (i > 0) or (j > 0):
105 | tb = argmin((D[i, j], D[i, j + 1], D[i + 1, j]))
106 | if tb == 0:
107 | i -= 1
108 | j -= 1
109 | elif tb == 1:
110 | track_hori = track_hori+1
111 | i -= 1
112 | else: # (tb == 2):
113 | track_verti = track_verti+1
114 | j -= 1
115 | p.insert(0, i)
116 | q.insert(0, j)
117 | return array(p), array(q)
118 |
119 |
120 | if __name__ == '__main__':
121 | w = inf
122 | s = 1.0
123 | if 1: # 1-D numeric
124 | from sklearn.metrics.pairwise import manhattan_distances
125 | x = [0, 0, 1, 1, 2, 4, 2, 1, 2, 0]
126 | y = [1, 1, 1, 2, 2, 2, 2, 3, 2, 0]
127 | dist_fun = manhattan_distances
128 | w = 1
129 | # s = 1.2
130 | elif 0: # 2-D numeric
131 | from sklearn.metrics.pairwise import euclidean_distances
132 | x = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [4, 3], [2, 3], [1, 1], [2, 2], [0, 1]]
133 | y = [[1, 0], [1, 1], [1, 1], [2, 1], [4, 3], [4, 3], [2, 3], [3, 1], [1, 2], [1, 0]]
134 | dist_fun = euclidean_distances
135 | else: # 1-D list of strings
136 | from nltk.metrics.distance import edit_distance
137 | # x = ['we', 'shelled', 'clams', 'for', 'the', 'chowder']
138 | # y = ['class', 'too']
139 | x = ['i', 'soon', 'found', 'myself', 'muttering', 'to', 'the', 'walls']
140 | y = ['see', 'drown', 'himself']
141 | # x = 'we talked about the situation'.split()
142 | # y = 'we talked about the situation'.split()
143 | dist_fun = edit_distance
144 | dist, cost, acc, path = dtw(x, y, dist_fun, w=w, s=s)
145 |
146 | # Vizualize
147 | from matplotlib import pyplot as plt
148 | plt.imshow(cost.T, origin='lower', cmap=plt.cm.Reds, interpolation='nearest')
149 | plt.plot(path[0], path[1], '-o') # relation
150 | plt.xticks(range(len(x)), x)
151 | plt.yticks(range(len(y)), y)
152 | plt.xlabel('x')
153 | plt.ylabel('y')
154 | plt.axis('tight')
155 | if isinf(w):
156 | plt.title('Minimum distance: {}, slope weight: {}'.format(dist, s))
157 | else:
158 | plt.title('Minimum distance: {}, window widht: {}, slope weight: {}'.format(dist, w, s))
159 | plt.show()
160 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/__pycache__/cf.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/parameter_cal/__pycache__/cf.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/__pycache__/cf.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/parameter_cal/__pycache__/cf.cpython-38.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/__pycache__/utils.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/parameter_cal/__pycache__/utils.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/__pycache__/utils.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/debug/parameter_cal/__pycache__/utils.cpython-38.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/cf.py:
--------------------------------------------------------------------------------
1 | # warp_width is the parameter of sigmoid 1 / (1 + math.exp(-x/a))
2 | vertical_mov = -3
3 | height_of_gaussian = 1.2
4 | ds_time = 3
5 | anchor_shift = 10
6 | refer_percent = 0.1
7 | query_percent = 0.5
8 | min_product = 10
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/convex_detect.py:
--------------------------------------------------------------------------------
1 | import linecache
2 | import numpy as np
3 | import scipy.signal
4 | import pandas as pd
5 | import matplotlib.pyplot as plt
6 | from parameter_cal import cf
7 | import math
8 | from parameter_cal.utils import find_peaks, eliminate_peaks
9 |
10 | def get_convex(indexes, inverse_indexes, combined_indexes):
11 | convex_group = []
12 | for i in range(len(combined_indexes) - 2):
13 | if combined_indexes[i] in inverse_indexes \
14 | and combined_indexes[i + 1] in indexes \
15 | and combined_indexes[i + 2] in inverse_indexes:
16 | convex_group.append([combined_indexes[i], combined_indexes[i + 1], combined_indexes[i + 2]])
17 | return convex_group
18 |
19 |
20 | def plot_convex(st, md, ed, series):
21 | _, ax = plt.subplots(1, 1, figsize=(8, 4))
22 | ax.plot(series[st:ed], 'b', lw=1)
23 | ax.plot(md - st, series[md], '+', mfc=None, mec='r', mew=2, ms=8)
24 |
25 |
26 | def plot_peaks(x, indexes, algorithm=None, mph=None, mpd=None):
27 | """Plot results of the peak dectection."""
28 | _, ax = plt.subplots(1, 1, figsize=(8, 4))
29 | ax.plot(x, 'b', lw=1)
30 | if indexes.size:
31 | label = 'peak'
32 | label = label + 's' if indexes.size > 1 else label
33 | ax.plot(indexes, x[indexes], '+', mfc=None, mec='r', mew=1, ms=4,
34 | label='%d %s' % (indexes.size, label))
35 | ax.legend(loc='best', framealpha=.5, numpoints=1)
36 | ax.set_xlim(-.02 * x.size, x.size * 1.02 - 1)
37 | ymin, ymax = x[np.isfinite(x)].min(), x[np.isfinite(x)].max()
38 | yrange = ymax - ymin if ymax > ymin else 1
39 | ax.set_ylim(ymin - 0.1 * yrange, ymax + 0.1 * yrange)
40 | ax.set_xlabel('Data #', fontsize=14)
41 | ax.set_ylabel('Amplitude', fontsize=14)
42 | ax.set_title('%s (mph=%s, mpd=%s)' % (algorithm, mph, mpd))
43 |
44 |
45 | file = linecache.getline('data/Beef_TRAIN', 1)
46 | y_list = file.split(',')
47 | # delete the index
48 | y_list.pop(0)
49 | y_list = [float(item) for item in y_list]
50 | upslope_grp = pd.DataFrame(columns=['st', 'ed', 'length', 'height'])
51 |
52 | # get the upward slope groups
53 | tvs_y_list = 0
54 | while tvs_y_list < len(y_list)-2:
55 | if y_list[tvs_y_list+2] > y_list[tvs_y_list+1] > y_list[tvs_y_list]:
56 | length = 3
57 | temp = tvs_y_list + 2
58 | while temp < len(y_list)-1:
59 | if y_list[temp+1]>y_list[temp]:
60 | length+=1
61 | temp+=1
62 | else:
63 | break
64 | upslope_grp.loc[len(upslope_grp)] = [tvs_y_list,temp,length,math.fabs(y_list[temp]-y_list[tvs_y_list])]
65 | tvs_y_list = temp
66 | tvs_y_list += 1
67 |
68 | cp_y_list = y_list
69 | inverse_y_list = [-item for item in y_list]
70 | # inverse_y_list = scipy.signal.savgol_filter(inverse_y_list, 11, 3)
71 | cp_ivs_y_list = inverse_y_list
72 | # should be 53 91 297 334 391
73 | # should be 73 263 373
74 | indexes, _ = scipy.signal.find_peaks(y_list, height=np.mean(y_list), distance=20)
75 | inverse_indexes, _ = scipy.signal.find_peaks(inverse_y_list, height=-0.5, distance=cf.warp_width)
76 |
77 | indexes = np.array(indexes)
78 | inverse_indexes = np.array(inverse_indexes)
79 | combined_indexes = np.sort(np.append(indexes, inverse_indexes))
80 |
81 | convex_group = get_convex(indexes, inverse_indexes, combined_indexes)
82 | convex_list = []
83 | for i in range(len(convex_group)):
84 | convex_list.append(y_list[convex_group[i][0]:convex_group[i][2]])
85 | plot_convex(0, convex_group[i][1] - convex_group[i][0], convex_group[i][2] - convex_group[i][0], convex_list[i])
86 | len_pre = convex_group[i][2] - convex_group[i][1]
87 | pre_x = np.linspace(0, len_pre, len_pre + 1) * 2
88 | after_x = np.linspace(0, 2 * len_pre, 2 * len_pre + 1)
89 | print(convex_group[i])
90 |
91 | plot_peaks(np.array(y_list), indexes, mph=1, mpd=1.8, algorithm='scipy.signal.find_peaks')
92 | plot_peaks(np.array(inverse_y_list), inverse_indexes, mph=1, mpd=1.9, algorithm='scipy.signal.find_peaks')
93 | plt.show()
94 |
95 | indexes2 = eliminate_peaks(indexes, y_list, 10, 0.25)
96 | plot_peaks(np.array(y_list), indexes2, mph=1, mpd=1.9, algorithm='scipy.signal.find_peaks')
97 | plt.show()
98 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/eventdtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | from scipy.misc import *
8 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_fact_align, get_reverse_dict, get_SS2, calculate_event, get_link_graph, true_align_graph, get_true_align
9 | from parameter_cal.utils import load_data, plot_warped_signals, cal_warped_signals
10 |
11 |
12 | def norm(x, y):
13 | #return math.fabs(x[1] - y[1])
14 | return math.fabs(x[1] - y[1])+math.fabs(x[2] - y[2])+math.fabs(x[3] - y[3])
15 |
16 |
17 | y_list = load_data('data/Beef_TRAIN')
18 | query, reference = cal_warped_signals(y_list)
19 |
20 | reference['upslope'] = 0
21 | reference['downslope'] = 0
22 |
23 | # plot warped signal
24 | xvals, yinterp = plot_warped_signals(reference, query, 1)
25 |
26 |
27 | # calculate the corresponding point pair
28 | query.drop('shift', axis=1)
29 | query.drop('t', axis=1)
30 | query2 = pd.DataFrame(yinterp)
31 | query2['aligned_index'] = 0
32 | query2['t'] = query['t']
33 | query2.columns = ['q', 'aligned_index', 't']
34 | query2['upslope'] = 0
35 | query2['downslope'] = 0
36 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
37 | for i in range(len(query2) - 1):
38 | for j in range(len(query['t2']) - 1):
39 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
40 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
41 | query2.loc[i, 'aligned_index'] = j
42 | else:
43 | query2.loc[i, 'aligned_index'] = j + 1
44 |
45 | refer_peak_indexes = np.array([211])
46 | query_peak_indexes = np.array([201])
47 | calculate_event(refer_peak_indexes, reference, 1)
48 | calculate_event(query_peak_indexes, query2, 1)
49 |
50 |
51 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values, query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
52 | true_align_dict = get_true_align(query2)
53 | fact_dict = get_fact_align(path)
54 | get_link_graph(reference, query2, path, -3)
55 | true_align_graph(true_align_dict, reference, query2, -3)
56 | reverse_dict = get_reverse_dict(path)
57 | print("path = " + str(len(path[0])))
58 | print('group = '+str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
59 | print("SS1 of dtw is " + str(get_W(path)))
60 | print("SS2 of dtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
61 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/original_eventdtw_downsample.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | import scipy.signal
8 | from scipy.misc import *
9 | from parameter_cal.utils import get_SS1, get_fact_align, get_reverse_dict, get_SS2, calculate_event, get_link_graph, \
10 | true_align_graph, load_data
11 | from parameter_cal.utils import plot_warped_signals, cal_warped_signals, draw_the_peaks, exp_decay
12 | import matplotlib.pyplot as plt
13 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
14 |
15 |
16 | def sigmoid0(x):
17 | return (4 * cf.warp_width) / (1 + math.exp(-x / cf.warp_width))
18 |
19 |
20 | sigmoid = np.vectorize(sigmoid0)
21 |
22 |
23 | def calculate_event(peak_indexes, df, time):
24 | slope_length = 20
25 | slope_weight = 1
26 | for peak_index in peak_indexes:
27 | for i in range(1, int(slope_length / time)):
28 | df.loc[peak_index - i, 'upslope'] = derivative(sigmoid, math.fabs(i * time), dx=1e-6) * slope_weight
29 | df.loc[peak_index + i, 'downslope'] = derivative(sigmoid, math.fabs(i * time), dx=1e-6) * slope_weight
30 | for peak_index in peak_indexes:
31 | df.loc[peak_index, 'upslope'] = 0
32 | df.loc[peak_index, 'downslope'] = 0
33 |
34 |
35 | def calculate_event0(peak_indexes, signal, time=1):
36 | slope_length = 20
37 | for peak_index in peak_indexes:
38 | center_time = signal.loc[peak_index, 't']
39 | signal.loc[peak_index, 'upslope'] = 1
40 | signal.loc[peak_index, 'downslope'] = 1
41 | for i in range(1, int(slope_length / time)):
42 | signal.loc[peak_index + i, 'downslope'] = exp_decay(
43 | math.fabs(signal.loc[peak_index + i, 't'] - center_time))
44 | signal.loc[peak_index - i, 'upslope'] = exp_decay(math.fabs(signal.loc[peak_index - i, 't'] - center_time))
45 |
46 |
47 | def get_matched_pairs(reference, query, refer_peaks, query_peaks, threshold=20):
48 | refer_len = len(refer_peaks)
49 | pairs = []
50 | for i in range(0, refer_len):
51 | refer_index = refer_peaks[i]
52 | refer_time = reference.loc[refer_index, 't']
53 | get = 0
54 | for index in query_peaks:
55 | query_time = query.loc[index, 't']
56 | if math.fabs(query_time - refer_time) > threshold:
57 | continue
58 | else:
59 | pairs.append([refer_index, index])
60 | get = 1
61 | break
62 | if get == 1:
63 | continue
64 | return pairs
65 |
66 |
67 | def norm(x, y):
68 | # return math.fabs(x[1] - y[1])
69 | return math.fabs(x[1] - y[1]) + math.fabs(x[2] - y[2]) + math.fabs(x[3] - y[3])
70 |
71 |
72 | # generate warped signal
73 | y_list = load_data('data/Beef_TRAIN')
74 | query, reference = cal_warped_signals(y_list)
75 |
76 | reference['upslope'] = 0
77 | reference['downslope'] = 0
78 |
79 | # plot warped signal
80 | # downsample times
81 | xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
82 |
83 | # calculate the corresponding point pair
84 | query.drop('shift', axis=1)
85 | query.drop('t', axis=1)
86 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
87 | query2['close_index'] = 0
88 | query2['upslope'] = 0
89 | query2['downslope'] = 0
90 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
91 | group_num_dict = get_group_number(true_align_dict, query)
92 | plt.show()
93 | true_align_graph(true_align_dict, reference, query2, -3)
94 |
95 | refer_peak_indexes = scipy.signal.find_peaks(y_list, height=np.mean(y_list), distance=20)
96 | query_peak_indexes = scipy.signal.find_peaks(query2.loc[:, 'q'], height=np.mean(query2.loc[:, 'q']), distance=20)
97 | pairs = get_matched_pairs(reference, query2, refer_peak_indexes[0], query_peak_indexes[0], 20)
98 | refer_indexes = []
99 | query_indexes = []
100 |
101 | for i in range(0, len(pairs)):
102 | refer_indexes.append(pairs[i][0])
103 | query_indexes.append(pairs[i][1])
104 |
105 | draw_the_peaks(reference, query2, refer_indexes, query_indexes, -3, 'Downsampled signal with peaks')
106 | calculate_event(refer_indexes, reference, 1)
107 | calculate_event(query_indexes, query2, cf.ds_time)
108 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values,
109 | query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
110 |
111 | get_link_graph(reference, query2, path, -3, 'Downsampled signal with EventDTW')
112 | fact_align_dict = get_fact_align(path)
113 | reverse_dict = get_reverse_dict(path)
114 | print("path = " + str(len(path[0])))
115 | print('group = ' + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
116 | print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
117 | print("SS2 of dtw is " + str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
118 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/parameter_cal_with_dDTW.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import numpy as np
4 | from parameter_cal import cf
5 | from dtw import dtw
6 | from scipy.misc import *
7 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_fact_align, get_SS2, get_reverse_dict, get_true_align, get_link_graph
8 | from parameter_cal.utils import plot_warped_signals, load_data, cal_warped_signals
9 | from parameter_cal.cf import anchor_shift
10 | import matplotlib.pyplot as plt
11 |
12 |
13 | def slope_col(query):
14 | # calculate the slope of query
15 | query_last = len(query) - 1
16 | query['slope'] = 0
17 | query.loc[1, 'slope'] = ((query.loc[1, 'q'] - query.loc[0, 'q']) + ((query.loc[2 , 'q'] - query.loc[1, 'q']) / 2)) / 2
18 | query.loc[0, 'slope'] = query.loc[1, 'slope']
19 | for i in range(2, query_last - 1):
20 | query.loc[i , 'slope'] = ((query.loc[i, 'q'] - query.loc[i-1, 'q']) + ((query.loc[i+1, 'q'] - query.loc[i, 'q']) / 2)) / 2
21 | query.loc[query_last - 1, 'slope'] = ((query.loc[query_last - 1, 'q'] - query.loc[query_last - 2, 'q']) + ((query.loc[query_last, 'q'] - query.loc[query_last - 1, 'q']) / 2)) / 2
22 | query.loc[query_last, 'slope'] = query.loc[query_last - 1, 'slope']
23 |
24 |
25 | def norm(x, y):
26 | return math.fabs(x[1] - y[1])
27 |
28 |
29 | def gaussian_bump(x, a=1):
30 | return math.exp(1 / (pow((x / a), 2) - 1))
31 |
32 |
33 | # when x = 0, sigmoid's derivative value is 1/4a
34 | def sigmoid0(x):
35 | return (4 * cf.warp_width) / (1 + math.exp(-x / cf.warp_width))
36 |
37 |
38 | sigmoid = np.vectorize(sigmoid0)
39 |
40 | y_list = load_data(True)
41 | query, reference = cal_warped_signals(y_list)
42 |
43 | # plot warped signal
44 | xvals, yinterp = plot_warped_signals(reference, query, 1)
45 |
46 | # store the corresponding point pair
47 | query.drop('shift', axis=1)
48 | query.drop('t', axis=1)
49 | query2 = pd.DataFrame(yinterp)
50 | query2['aligned_index'] = 0
51 | query2['t'] = query['t']
52 | query2.columns = ['q', 'aligned_index', 't']
53 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
54 | for i in range(len(query2) - 1):
55 | for j in range(len(query['t2']) - 1):
56 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
57 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
58 | query2.loc[i, 'aligned_index'] = j
59 | else:
60 | query2.loc[i, 'aligned_index'] = j + 1
61 |
62 |
63 | slope_col(query2)
64 | slope_col(reference)
65 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'slope']].values, query2[['t', 'slope']].values, dist=norm)
66 | get_link_graph(reference, query2, path, -3)
67 | true_align_dict = get_true_align(query2)
68 | fact_dict = get_fact_align(path)
69 | reverse_dict = get_reverse_dict(path)
70 | print("error rate of dtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
71 | print("W of ddtw is " + str(get_W(path)))
72 | print("SS2 of ddtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
73 |
--------------------------------------------------------------------------------
/Signal-Alignment/debug/parameter_cal/parameter_cal_with_dtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_SS2, get_fact_align, get_reverse_dict, get_true_align, get_link_graph, load_data
7 | from parameter_cal.utils import plot_warped_signals, cal_warped_signals
8 | from dtw import dtw
9 | from parameter_cal.cf import anchor_index, anchor_shift
10 | from scipy.misc import *
11 | import matplotlib.pyplot as plt
12 |
13 |
14 | def norm(x, y):
15 | return math.fabs(x[1] - y[1])
16 |
17 |
18 | y_list = load_data(True)
19 | query, reference = cal_warped_signals(y_list)
20 |
21 |
22 | # plot warped signal
23 | xvals, yinterp = plot_warped_signals(reference, query, 1)
24 |
25 |
26 | # store the corresponding point pair
27 | query.drop('shift', axis=1)
28 | query.drop('t', axis=1)
29 | query2 = pd.DataFrame(yinterp)
30 | query2['aligned_index'] = 0
31 | query2['t'] = query['t']
32 | query2.columns = ['q', 'aligned_index', 't']
33 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
34 | for i in range(len(query2) - 1):
35 | for j in range(len(query['t2']) - 1):
36 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
37 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
38 | query2.loc[i, 'aligned_index'] = j
39 | else:
40 | query2.loc[i, 'aligned_index'] = j + 1
41 |
42 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q']].values, query2[['t', 'q']].values, dist=norm)
43 | get_link_graph(reference, query2, path, -3)
44 | true_align_dict = get_true_align(query2)
45 | fact_dict = get_fact_align(path)
46 | reverse_dict = get_reverse_dict(path)
47 | print("error rate of dtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
48 | print("W of dtw is " + str(get_W(path)))
49 | print("SS2 of dtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/__pycache__/utils.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/downsample/__pycache__/utils.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/downsample_with_dDTW.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | from parameter_cal import cf
4 | from dtw import dtw
5 | from scipy.misc import *
6 | from downsample.utils import get_true_aligned, get_group_number
7 | from parameter_cal.utils import get_SS2, get_group_devi, get_SS1, get_fact_align, get_reverse_dict, get_link_graph
8 | from parameter_cal.utils import load_data, cal_warped_signals, write_result_file
9 | from downsample.utils import slope_col, reference_slope_col, get_k_accuracy, get_warped_signals
10 | import os
11 |
12 |
13 | def norm(x, y):
14 | return math.fabs(x[1] - y[1])
15 |
16 |
17 | def ddtw(file_name, line_num, df):
18 | file_name = 'data/' + file_name
19 | y_list = load_data(file_name, line_num)
20 | query, reference = cal_warped_signals(y_list)
21 |
22 | # plot warped signal
23 | xvals, yinterp = get_warped_signals(query, cf.ds_time)
24 |
25 | # calculate the corresponding point pair
26 | query.drop(['shift', 't'], axis=1)
27 | query2 = pd.DataFrame({'t':xvals, 'q':yinterp})
28 | query2['close_index'] = 0
29 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
30 | group_num_dict = get_group_number(true_align_dict, query)
31 |
32 | reference_slope_col(reference, 1)
33 | slope_col(query2)
34 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'avg_slope']].values, query2[['t', 'slope']].values, dist=norm)
35 | fact_align_dict = get_fact_align(path)
36 | reverse_dict = get_reverse_dict(path)
37 | error_rate = get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)
38 | SS1 = get_SS1(fact_align_dict, cf.ds_time)
39 | SS2 = get_SS2(fact_align_dict, reverse_dict, cf.ds_time)
40 | df.loc[line_num] = [error_rate, SS1, SS2]
41 | return df
42 |
43 | if __name__ == "__main__":
44 | # generate warped signal
45 | os.chdir(os.path.abspath('..'))
46 | data_dir = os.getcwd()+'\\data\\'
47 | oslist = [f for f in os.listdir(data_dir) if os.path.isfile(data_dir+f)]
48 | # target_abs_directory = os.getcwd() + '\\csv\\' + 'result.csv'
49 | # df = pd.read_csv(target_abs_directory, engine='python')
50 | # print(df)
51 | # for i in range(0, len(oslist)):
52 | for i in range(0, 84):
53 | event_result = pd.DataFrame(columns=['Error rate','SS1','SS2'])
54 | for j in range(1, 16):
55 | event_result = ddtw(oslist[i], j, event_result)
56 | print(event_result.mean())
57 | print("file" + str(i)+"this is len"+str(len(event_result)))
58 | write_result_file('result.csv', 'dDTW', oslist[i], event_result.mean())
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/downsample_with_dtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | import os
8 | from scipy.misc import *
9 | from parameter_cal.utils import get_SS1, get_fact_align, get_reverse_dict, get_SS2, write_result_file
10 | from parameter_cal.utils import load_data, cal_warped_signals
11 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy, get_warped_signals
12 |
13 |
14 | def norm(x, y):
15 | return math.fabs(x[1] - y[1])
16 |
17 |
18 | def pkg_dtw(file_name, line_num, df):
19 | file_name = 'data/' + file_name
20 | y_list = load_data(file_name, line_num)
21 | query, reference = cal_warped_signals(y_list)
22 |
23 | # plot warped signal
24 | # downsample times
25 | xvals, yinterp = get_warped_signals(query, cf.ds_time)
26 |
27 | # calculate the corresponding point pair
28 | query.drop(['shift', 't'], axis=1)
29 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
30 | query2['close_index'] = 0
31 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
32 | group_num_dict = get_group_number(true_align_dict, query)
33 |
34 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q']].values, query2[['t', 'q']].values, dist=norm)
35 | fact_align_dict = get_fact_align(path)
36 | reverse_dict = get_reverse_dict(path)
37 | error_rate = get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)
38 | SS1 = get_SS1(fact_align_dict, cf.ds_time)
39 | SS2 = get_SS2(fact_align_dict, reverse_dict, cf.ds_time)
40 | df.loc[line_num] = [error_rate, SS1, SS2]
41 | return df
42 |
43 |
44 | if __name__ == "__main__":
45 | # generate warped signal
46 | os.chdir(os.path.abspath('..'))
47 | data_dir = os.getcwd() + '\\data\\'
48 | oslist = [f for f in os.listdir(data_dir) if os.path.isfile(data_dir+f)]
49 | # for i in range(0, len(oslist)):
50 | for i in range(0, 84):
51 | event_result = pd.DataFrame(columns=['Error rate','SS1','SS2'])
52 | for j in range(1, 16):
53 | event_result = pkg_dtw(oslist[i], j, event_result)
54 | print(event_result.mean())
55 | print('file'+str(i))
56 | write_result_file('result.csv', 'DTW', oslist[i], event_result.mean())
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/downsample_with_eventdtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import os, sys
4 | import linecache
5 | import numpy as np
6 | from parameter_cal import cf
7 | from dtw import dtw
8 | from parameter_cal.utils import get_fact_align, get_reverse_dict, calculate_event, load_data, edge_matching, write_result_file
9 | from parameter_cal.utils import get_SS1, get_SS2, cal_warped_signals, get_upslope_endings, get_downslope_endings
10 | from downsample.utils import get_true_aligned, get_k_accuracy, get_group_number, get_warped_signals
11 |
12 |
13 | def norm(x, y):
14 | # return math.fabs(x[1] - y[1])
15 | return math.fabs(x[1] - y[1]) + math.fabs(x[2] - y[2]) + math.fabs(x[3] - y[3])
16 |
17 |
18 | def event_dtw(file_name, line_num, df):
19 | file_name = 'data/' + file_name
20 | y_list = load_data(file_name, line_num)
21 | query, reference = cal_warped_signals(y_list)
22 |
23 | reference['upslope'] = 0
24 | reference['downslope'] = 0
25 |
26 | # plot warped signal
27 | # downsample times
28 | xvals, yinterp = get_warped_signals(query, cf.ds_time)
29 |
30 | # calculate the corresponding point pair
31 | query.drop('shift', axis=1)
32 | query.drop('t', axis=1)
33 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
34 | query2['close_index'] = 0
35 | query2['upslope'] = 0
36 | query2['downslope'] = 0
37 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
38 | group_num_dict = get_group_number(true_align_dict, query)
39 |
40 | raw_reference_uslope, reference_upslope = get_upslope_endings(reference['q'], cf.refer_percent)
41 | raw_query_uslope, query_upslope = get_upslope_endings(query2['q'], cf.query_percent)
42 |
43 | raw_reference_downlope, reference_downslope = get_downslope_endings(reference['q'], cf.refer_percent)
44 | raw_query_downlope, query_downslope = get_downslope_endings(query2['q'], cf.query_percent)
45 |
46 | rising_edge_grps = edge_matching(reference, query2, reference_upslope, query_upslope)
47 | down_edge_grps = edge_matching(reference, query2, reference_downslope, query_downslope)
48 |
49 | calculate_event(rising_edge_grps, reference, query2, True)
50 | calculate_event(down_edge_grps, reference, query2, False)
51 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values,
52 | query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
53 | fact_align_dict = get_fact_align(path)
54 | reverse_dict = get_reverse_dict(path)
55 | error_rate = get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)
56 | SS1 = get_SS1(fact_align_dict, cf.ds_time)
57 | SS2 = get_SS2(fact_align_dict, reverse_dict, cf.ds_time)
58 | df.loc[line_num] = [error_rate, SS1, SS2]
59 | return df
60 |
61 |
62 | if __name__ == "__main__":
63 | # generate warped signal
64 | os.chdir(os.path.abspath('..'))
65 | data_dir = os.getcwd() + '\\data\\'
66 | oslist = [f for f in os.listdir(data_dir) if os.path.isfile(data_dir + f)]
67 | # target_abs_directory = os.getcwd() + '\\csv\\' + 'result.csv'
68 | # df = pd.read_csv(target_abs_directory, engine='python')
69 | # print(df)
70 | # for i in range(0, len(oslist)):
71 | for i in range(0,84):
72 | event_result = pd.DataFrame(columns=['Error rate', 'SS1', 'SS2'])
73 | for j in range(1, 16):
74 | event_result = event_dtw(oslist[i], j, event_result)
75 | print('group' + str(j))
76 | print(event_result.mean())
77 | print("file" + str(i) + "this is len" + str(len(event_result)))
78 | write_result_file('result.csv', 'EventDTW', oslist[i], event_result.mean())
79 |
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/downsample_with_shapedtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from scipy import stats
6 | from parameter_cal import cf
7 | from dtw import dtw
8 | import os
9 | from scipy.misc import *
10 | from sdtw.config import sub_len, nBlocks
11 | from sdtw.utils import cal_descriptor, samplingSequences, norm
12 | from parameter_cal.utils import get_fact_align, get_reverse_dict, get_SS2, get_SS1, get_link_graph, load_data
13 | from parameter_cal.utils import load_data, cal_warped_signals, write_result_file
14 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy, get_warped_signals
15 |
16 |
17 | def pkg_shapedtw(file_name, line_num, df):
18 | file_name = 'data/' + file_name
19 | y_list = load_data(file_name, line_num)
20 | query, reference = cal_warped_signals(y_list)
21 |
22 | # plot warped signal
23 | xvals, yinterp = get_warped_signals(query, cf.ds_time)
24 |
25 | # normalize the signal
26 | reference_norm = stats.zscore(reference['q'])
27 | yinterp_norm = stats.zscore(yinterp)
28 |
29 | # store the corresponding point pair
30 | query.drop(['shift', 't'], axis=1)
31 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
32 | query2['close_index'] = 0
33 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
34 | group_num_dict = get_group_number(true_align_dict, query)
35 |
36 | refer_subsequences = samplingSequences(reference_norm, sub_len)
37 | query_subsequences = samplingSequences(yinterp_norm, int(sub_len / cf.ds_time))
38 | refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
39 | query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
40 | refer_nsubsequences = len(refer_subsequences)
41 | query_nsubsequences = len(query_subsequences)
42 |
43 | for i in range(refer_nsubsequences):
44 | sub_seq = refer_subsequences[i]
45 | refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)
46 |
47 | for i in range(query_nsubsequences):
48 | sub_seq = query_subsequences[i]
49 | query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len / cf.ds_time))
50 |
51 | d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
52 | fact_align_dict = get_fact_align(path)
53 | reverse_dict = get_reverse_dict(path)
54 | error_rate = get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)
55 | SS1 = get_SS1(fact_align_dict, cf.ds_time)
56 | SS2 = get_SS2(fact_align_dict, reverse_dict, cf.ds_time)
57 | df.loc[line_num] = [error_rate, SS1, SS2]
58 | return df
59 |
60 | if __name__ == "__main__":
61 | # generate warped signal
62 | os.chdir(os.path.abspath('..'))
63 | data_dir = os.getcwd() + '\\data\\'
64 | oslist = [f for f in os.listdir(data_dir) if os.path.isfile(data_dir+f)]
65 | # for i in range(0, len(oslist)):
66 | for i in range(0, 84):
67 | event_result = pd.DataFrame(columns=['Error rate','SS1','SS2'])
68 | for j in range(1, 16):
69 | event_result = pkg_shapedtw(oslist[i], j, event_result)
70 | print(event_result.mean())
71 | print('file'+str(i))
72 | write_result_file('result.csv', 'shapeDTW', oslist[i], event_result.mean())
73 |
--------------------------------------------------------------------------------
/Signal-Alignment/downsample/utils.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import math
3 | from parameter_cal.utils import get_group_devi, get_SS1, get_SS2
4 | from parameter_cal import cf
5 | import pandas as pd
6 | import matplotlib.pyplot as plt
7 | from matplotlib.lines import Line2D
8 | from matplotlib.patches import Patch
9 |
10 |
11 | def get_group_len(query_st, query2_checkpoint, ds_time, query, query2):
12 | group_len = 0
13 | for i in range(0, ds_time):
14 | group_len += math.sqrt(pow((query2['t'][query2_checkpoint] - query['t2'][i+query_st]), 2) + pow((query2['q'][query2_checkpoint] - query['q'][i+query_st]), 2))
15 | return group_len
16 |
17 |
18 | def get_true_aligned(ds_time, query, query2):
19 | if math.floor(ds_time) == math.ceil(ds_time):
20 | ds_time = int(ds_time)
21 | dict = {}.fromkeys(range(0, len(query2['t'])))
22 | for i in range(len(query2['t'])):
23 | dict[i] = np.array([])
24 | # find the closest index
25 | for i in range(len(query2)):
26 | for j in range(len(query['t']) - 1):
27 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
28 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
29 | query2.loc[i, 'close_index'] = j
30 | dict[i] = np.append(dict[i], j)
31 | else:
32 | query2.loc[i, 'close_index'] = j + 1
33 | dict[i] = np.append(dict[i], j+1)
34 | if query2['t'][i] > query['t2'].iloc[-1]:
35 | query2.loc[i, 'close_index'] = len(query) - 1
36 | elif query2['t'][i] < query['t2'].iloc[0]:
37 | query2.loc[i, 'close_index'] = 0
38 | dict[len(query2['t'])-1] = np.array([len(query)-1])
39 | for i in range(len(query2['t'])):
40 | min_len = np.inf
41 | center = int(dict[i][0])
42 | for j in range(-ds_time+1, 1):
43 | st, ed = center+j,center+j+ds_time-1
44 | if st < 0 or ed >= len(query['t2']):
45 | continue
46 | # print(i, st, center, j)
47 | group_len = get_group_len(st, i, ds_time, query, query2)
48 | if group_len < min_len:
49 | dict[i] = np.array(list(range(center+j, center+j+ds_time)))
50 | min_len = group_len
51 | return dict
52 |
53 |
54 | def get_group_number(true_align_dict, query):
55 | diction = {}.fromkeys(range(0, len(query['q'])))
56 | for i in range(len(query['q'])):
57 | diction[i] = np.array([])
58 | diction = {}.fromkeys(range(0, len(query['q'])))
59 | for i in range(len(query['q'])):
60 | diction[i] = np.array([])
61 | for i in range(len(true_align_dict)):
62 | for item in true_align_dict[i]:
63 | diction[item] = np.append(diction[item], i)
64 | # modify those that did not find their group
65 | for i in range(len(diction)):
66 | if len(diction[i]) == 0:
67 | diction[i] = np.append(diction[i], diction[i - 1][0])
68 | return diction
69 |
70 |
71 | def get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict):
72 | sum = 0
73 | consider_num = 0
74 | query_number = len(fact_align_dict)
75 | for i in range(len(fact_align_dict)):
76 | for item in fact_align_dict[i]:
77 | consider_num += 1
78 | if item in true_align_dict[i]:
79 | sum += 0
80 | else:
81 | # search the group number
82 | group_devi = get_group_devi(item, group_num_dict,i)
83 | sum += group_devi
84 | # sum+=min(np.abs(item-true_align_dict[i]))
85 | return 2 * sum / ((query_number * (query_number - 1)) * (1+math.fabs(cf.ds_time)))
86 |
87 |
88 | def slope_col(query):
89 | # calculate the slope of query
90 | query_last = len(query) - 1
91 | query['slope'] = 0
92 | query.loc[1, 'slope'] = ((query.loc[1, 'q'] - query.loc[0, 'q']) + ((query.loc[2 , 'q'] - query.loc[1, 'q']) / 2)) / 2
93 | query.loc[0, 'slope'] = query.loc[1, 'slope']
94 | for i in range(2, query_last - 1):
95 | query.loc[i, 'slope'] = ((query.loc[i, 'q'] -query.loc[i-1, 'q']) + ((query.loc[i+1, 'q'] - query.loc[i, 'q']) / 2)) / 2
96 | query.loc[query_last - 1, 'slope'] = ((query.loc[query_last - 1, 'q'] - query.loc[query_last - 2, 'q']) + (
97 | (query.loc[query_last, 'q'] - query.loc[query_last - 1, 'q']) / 2)) / 2
98 | query.loc[query_last, 'slope'] = query.loc[query_last - 1, 'slope']
99 |
100 |
101 | def reference_slope_col(query, ds_time):
102 | slope_col(query)
103 | query['avg_slope'] = 0
104 | left_right = ds_time
105 | st = 0 + left_right
106 | ed = len(query) - 1 - left_right
107 | for i in range(0, ed+1):
108 | query.loc[i, 'avg_slope'] = (query.loc[i+left_right, 'q'] - query.loc[i, 'q']) / 2
109 | for i in range(ed+1, len(query) - 1):
110 | query.loc[i, 'avg_slope'] = query.loc[i, 'slope']
111 |
112 |
113 | def get_warped_signals(query, ds_time):
114 | if ds_time == 1:
115 | xvals = query['t']
116 | xvals = np.array(xvals)
117 | else:
118 | xvals = np.linspace(query.loc[0,'t2'], query.iloc[-1]['t2'], math.floor(len(query['t']) / cf.ds_time))
119 | x = query['t2']
120 | y = query['q']
121 | yinterp = np.array(np.interp(xvals, x, y))
122 | return xvals, yinterp
123 |
124 |
125 | def connect_edges(rising_edge_grps, raw_reference_uslope):
126 | for i in range(len(rising_edge_grps)):
127 | st_conct = int(rising_edge_grps.loc[i, 'refer_st'])
128 | ed_conct = int(rising_edge_grps.loc[i, 'refer_ed'])
129 | for j in range(len(raw_reference_uslope)):
130 | if math.fabs(st_conct - raw_reference_uslope.iloc[j]['ed']) <= 2:
131 | rising_edge_grps.iloc[i]['refer_st'] = raw_reference_uslope.iloc[j]['st']
132 | elif math.fabs(ed_conct - raw_reference_uslope.iloc[j]['st']) <= 2:
133 | rising_edge_grps.iloc[i]['refer_ed'] = raw_reference_uslope.iloc[j]['ed']
134 | return rising_edge_grps
135 |
136 |
137 | def get_matched_graph(rising_edge_grps, down_edge_grps, x, y, vertical_mov, title=None):
138 | fig, ax = plt.subplots(1, 1, figsize=(25, 12))
139 | legend_elements = [Line2D([0], [0], marker='o',color='w',label=' ',markerfacecolor='black',markersize=15),
140 | Line2D([0], [0], marker='o',color='w',label=' ',markerfacecolor='blue',markersize=20),
141 | Line2D([0], [0], color='r', lw=4),
142 | Line2D([0], [0], color='cyan', lw=4)
143 | ]
144 | ax.scatter(x['t'], x['q'], c='k', marker='.')
145 | ax.scatter(y['t'], y['q'] + vertical_mov, c='b', s=160, marker='.')
146 | b = ax.get_position()
147 | ax.legend(ncol=2, handles = legend_elements, fontsize=40, frameon=False, loc='lower left', bbox_to_anchor=(0,1.05))
148 | for i in range(0, len(rising_edge_grps)):
149 | refer_st = int(rising_edge_grps.iloc[i]['refer_st'])
150 | refer_ed = int(rising_edge_grps.iloc[i]['refer_ed'])
151 | query_st = int(rising_edge_grps.iloc[i]['query_st'])
152 | query_ed = int(rising_edge_grps.iloc[i]['query_ed'])
153 | ax.plot(x['t'].loc[refer_st:refer_ed], x['q'].loc[refer_st:refer_ed], color='r', linewidth=5)
154 | ax.plot(y['t'].loc[query_st:query_ed], y['q'].loc[query_st:query_ed] + vertical_mov, color='r', linewidth=5)
155 |
156 | for i in range(0, len(down_edge_grps)):
157 | refer_st = int(down_edge_grps.iloc[i]['refer_st'])
158 | refer_ed = int(down_edge_grps.iloc[i]['refer_ed'])
159 | query_st = int(down_edge_grps.iloc[i]['query_st'])
160 | query_ed = int(down_edge_grps.iloc[i]['query_ed'])
161 | ax.plot(x['t'].loc[refer_st:refer_ed], x['q'].loc[refer_st:refer_ed], color='cyan', linewidth=5)
162 | ax.plot(y['t'].loc[query_st:query_ed], y['q'].loc[query_st:query_ed] + vertical_mov, color='cyan', linewidth=5)
163 | ax.set_title(title, fontsize='30')
164 | ax.spines['top'].set_visible(False)
165 | ax.spines['bottom'].set_visible(False)
166 | ax.spines['left'].set_visible(False)
167 | ax.spines['right'].set_visible(False)
168 | ax.set_xticks([])
169 | ax.set_yticks([])
170 | plt.show()
--------------------------------------------------------------------------------
/Signal-Alignment/dtw.py:
--------------------------------------------------------------------------------
1 | from numpy import array, zeros, full, argmin, inf, ndim
2 | from scipy.spatial.distance import cdist
3 | from math import isinf
4 |
5 | def dtw(x, y, dist, warp=1, w=inf, s=1.0):
6 | """
7 | Computes Dynamic Time Warping (DTW) of two sequences.
8 |
9 | :param array x: N1*M array
10 | :param array y: N2*M array
11 | :param func dist: distance used as cost measure
12 | :param int warp: how many shifts are computed.
13 | :param int w: window size limiting the maximal distance between indices of matched entries |i,j|.
14 | :param float s: weight applied on off-diagonal moves of the path. As s gets larger, the warping path is increasingly biased towards the diagonal
15 | Returns the minimum distance, the cost matrix, the accumulated cost matrix, and the wrap path.
16 | """
17 | assert len(x)
18 | assert len(y)
19 | assert isinf(w) or (w >= abs(len(x) - len(y)))
20 | assert s > 0
21 | r, c = len(x), len(y)
22 | if not isinf(w):
23 | D0 = full((r + 1, c + 1), inf)
24 | for i in range(1, r + 1):
25 | D0[i, max(1, i - w):min(c + 1, i + w + 1)] = 0
26 | D0[0, 0] = 0
27 | else:
28 | D0 = zeros((r + 1, c + 1))
29 | D0[0, 1:] = inf
30 | D0[1:, 0] = inf
31 | D1 = D0[1:, 1:] # view
32 | for i in range(r):
33 | for j in range(c):
34 | if (isinf(w) or (max(0, i - w) <= j <= min(c, i + w))):
35 | D1[i, j] = dist(x[i], y[j])
36 | C = D1.copy()
37 | jrange = range(c)
38 | for i in range(r):
39 | if not isinf(w):
40 | jrange = range(max(0, i - w), min(c, i + w + 1))
41 | for j in jrange:
42 | min_list = [D0[i, j]]
43 | for k in range(1, warp + 1):
44 | i_k = min(i + k, r)
45 | j_k = min(j + k, c)
46 | min_list += [D0[i_k, j] * s, D0[i, j_k] * s]
47 | D1[i, j] += min(min_list)
48 | if len(x) == 1:
49 | path = zeros(len(y)), range(len(y))
50 | elif len(y) == 1:
51 | path = range(len(x)), zeros(len(x))
52 | else:
53 | path = _traceback(D0)
54 | return D1[-1, -1] / sum(D1.shape), C, D1, path
55 | # return D1[-1, -1], C, D1, path
56 |
57 | def accelerated_dtw(x, y, dist, warp=1):
58 | """
59 | Computes Dynamic Time Warping (DTW) of two sequences in a faster way.
60 | Instead of iterating through each element and calculating each distance,
61 | this uses the cdist function from scipy (https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html)
62 |
63 | :param array x: N1*M array
64 | :param array y: N2*M array
65 | :param string or func dist: distance parameter for cdist. When string is given, cdist uses optimized functions for the distance metrics.
66 | If a string is passed, the distance function can be 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'wminkowski', 'yule'.
67 | :param int warp: how many shifts are computed.
68 | Returns the minimum distance, the cost matrix, the accumulated cost matrix, and the wrap path.
69 | """
70 | assert len(x)
71 | assert len(y)
72 | if ndim(x) == 1:
73 | x = x.reshape(-1, 1)
74 | if ndim(y) == 1:
75 | y = y.reshape(-1, 1)
76 | r, c = len(x), len(y)
77 | D0 = zeros((r + 1, c + 1))
78 | D0[0, 1:] = inf
79 | D0[1:, 0] = inf
80 | D1 = D0[1:, 1:]
81 | D0[1:, 1:] = cdist(x, y, dist)
82 | C = D1.copy()
83 | for i in range(r):
84 | for j in range(c):
85 | min_list = [D0[i, j]]
86 | for k in range(1, warp + 1):
87 | min_list += [D0[min(i + k, r), j],
88 | D0[i, min(j + k, c)]]
89 | D1[i, j] += min(min_list)
90 | if len(x) == 1:
91 | path = zeros(len(y)), range(len(y))
92 | elif len(y) == 1:
93 | path = range(len(x)), zeros(len(x))
94 | else:
95 | path = _traceback(D0)
96 | return D1[-1, -1] / sum(D1.shape), C, D1, path
97 |
98 |
99 | def _traceback(D):
100 | i, j = array(D.shape) - 2
101 | p, q = [i], [j]
102 | track_verti = 0
103 | track_hori = 0
104 | while (i > 0) or (j > 0):
105 | tb = argmin((D[i, j], D[i, j + 1], D[i + 1, j]))
106 | if tb == 0:
107 | i -= 1
108 | j -= 1
109 | elif tb == 1:
110 | track_hori = track_hori+1
111 | i -= 1
112 | else: # (tb == 2):
113 | track_verti = track_verti+1
114 | j -= 1
115 | p.insert(0, i)
116 | q.insert(0, j)
117 | return array(p), array(q)
118 |
119 |
120 | if __name__ == '__main__':
121 | w = inf
122 | s = 1.0
123 | if 1: # 1-D numeric
124 | from sklearn.metrics.pairwise import manhattan_distances
125 | x = [0, 0, 1, 1, 2, 4, 2, 1, 2, 0]
126 | y = [1, 1, 1, 2, 2, 2, 2, 3, 2, 0]
127 | dist_fun = manhattan_distances
128 | w = 1
129 | # s = 1.2
130 | elif 0: # 2-D numeric
131 | from sklearn.metrics.pairwise import euclidean_distances
132 | x = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [4, 3], [2, 3], [1, 1], [2, 2], [0, 1]]
133 | y = [[1, 0], [1, 1], [1, 1], [2, 1], [4, 3], [4, 3], [2, 3], [3, 1], [1, 2], [1, 0]]
134 | dist_fun = euclidean_distances
135 | else: # 1-D list of strings
136 | from nltk.metrics.distance import edit_distance
137 | # x = ['we', 'shelled', 'clams', 'for', 'the', 'chowder']
138 | # y = ['class', 'too']
139 | x = ['i', 'soon', 'found', 'myself', 'muttering', 'to', 'the', 'walls']
140 | y = ['see', 'drown', 'himself']
141 | # x = 'we talked about the situation'.split()
142 | # y = 'we talked about the situation'.split()
143 | dist_fun = edit_distance
144 | dist, cost, acc, path = dtw(x, y, dist_fun, w=w, s=s)
145 |
146 | # Vizualize
147 | from matplotlib import pyplot as plt
148 | plt.imshow(cost.T, origin='lower', cmap=plt.cm.Reds, interpolation='nearest')
149 | plt.plot(path[0], path[1], '-o') # relation
150 | plt.xticks(range(len(x)), x)
151 | plt.yticks(range(len(y)), y)
152 | plt.xlabel('x')
153 | plt.ylabel('y')
154 | plt.axis('tight')
155 | if isinf(w):
156 | plt.title('Minimum distance: {}, slope weight: {}'.format(dist, s))
157 | else:
158 | plt.title('Minimum distance: {}, window widht: {}, slope weight: {}'.format(dist, w, s))
159 | plt.show()
160 |
--------------------------------------------------------------------------------
/Signal-Alignment/figure/Alignment.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/figure/Alignment.jpg
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/__pycache__/cf.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/parameter_cal/__pycache__/cf.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/__pycache__/utils.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/parameter_cal/__pycache__/utils.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/cf.py:
--------------------------------------------------------------------------------
1 | # warp_width is the parameter of sigmoid 1 / (1 + math.exp(-x/a))
2 | vertical_mov = -3
3 | height_of_gaussian = 1.2
4 | ds_time = 3
5 | anchor_shift = 10
6 | refer_percent = 0.1
7 | query_percent = 0.5
8 | min_product = 10
9 |
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/convex_detect.py:
--------------------------------------------------------------------------------
1 | import linecache
2 | import numpy as np
3 | import scipy.signal
4 | import pandas as pd
5 | import matplotlib.pyplot as plt
6 | from parameter_cal import cf
7 | import math
8 | from parameter_cal.utils import find_peaks, eliminate_peaks
9 |
10 | def get_convex(indexes, inverse_indexes, combined_indexes):
11 | convex_group = []
12 | for i in range(len(combined_indexes) - 2):
13 | if combined_indexes[i] in inverse_indexes \
14 | and combined_indexes[i + 1] in indexes \
15 | and combined_indexes[i + 2] in inverse_indexes:
16 | convex_group.append([combined_indexes[i], combined_indexes[i + 1], combined_indexes[i + 2]])
17 | return convex_group
18 |
19 |
20 | def plot_convex(st, md, ed, series):
21 | _, ax = plt.subplots(1, 1, figsize=(8, 4))
22 | ax.plot(series[st:ed], 'b', lw=1)
23 | ax.plot(md - st, series[md], '+', mfc=None, mec='r', mew=2, ms=8)
24 |
25 |
26 | def plot_peaks(x, indexes, algorithm=None, mph=None, mpd=None):
27 | """Plot results of the peak dectection."""
28 | _, ax = plt.subplots(1, 1, figsize=(8, 4))
29 | ax.plot(x, 'b', lw=1)
30 | if indexes.size:
31 | label = 'peak'
32 | label = label + 's' if indexes.size > 1 else label
33 | ax.plot(indexes, x[indexes], '+', mfc=None, mec='r', mew=1, ms=4,
34 | label='%d %s' % (indexes.size, label))
35 | ax.legend(loc='best', framealpha=.5, numpoints=1)
36 | ax.set_xlim(-.02 * x.size, x.size * 1.02 - 1)
37 | ymin, ymax = x[np.isfinite(x)].min(), x[np.isfinite(x)].max()
38 | yrange = ymax - ymin if ymax > ymin else 1
39 | ax.set_ylim(ymin - 0.1 * yrange, ymax + 0.1 * yrange)
40 | ax.set_xlabel('Data #', fontsize=14)
41 | ax.set_ylabel('Amplitude', fontsize=14)
42 | ax.set_title('%s (mph=%s, mpd=%s)' % (algorithm, mph, mpd))
43 |
44 |
45 | file = linecache.getline('data/Beef_TRAIN', 1)
46 | y_list = file.split(',')
47 | # delete the index
48 | y_list.pop(0)
49 | y_list = [float(item) for item in y_list]
50 | upslope_grp = pd.DataFrame(columns=['st', 'ed', 'length', 'height'])
51 |
52 | # get the upward slope groups
53 | tvs_y_list = 0
54 | while tvs_y_list < len(y_list)-2:
55 | if y_list[tvs_y_list+2] > y_list[tvs_y_list+1] > y_list[tvs_y_list]:
56 | length = 3
57 | temp = tvs_y_list + 2
58 | while temp < len(y_list)-1:
59 | if y_list[temp+1]>y_list[temp]:
60 | length+=1
61 | temp+=1
62 | else:
63 | break
64 | upslope_grp.loc[len(upslope_grp)] = [tvs_y_list,temp,length,math.fabs(y_list[temp]-y_list[tvs_y_list])]
65 | tvs_y_list = temp
66 | tvs_y_list += 1
67 |
68 | cp_y_list = y_list
69 | inverse_y_list = [-item for item in y_list]
70 | # inverse_y_list = scipy.signal.savgol_filter(inverse_y_list, 11, 3)
71 | cp_ivs_y_list = inverse_y_list
72 | # should be 53 91 297 334 391
73 | # should be 73 263 373
74 | indexes, _ = scipy.signal.find_peaks(y_list, height=np.mean(y_list), distance=20)
75 | inverse_indexes, _ = scipy.signal.find_peaks(inverse_y_list, height=-0.5, distance=cf.warp_width)
76 |
77 | indexes = np.array(indexes)
78 | inverse_indexes = np.array(inverse_indexes)
79 | combined_indexes = np.sort(np.append(indexes, inverse_indexes))
80 |
81 | convex_group = get_convex(indexes, inverse_indexes, combined_indexes)
82 | convex_list = []
83 | for i in range(len(convex_group)):
84 | convex_list.append(y_list[convex_group[i][0]:convex_group[i][2]])
85 | plot_convex(0, convex_group[i][1] - convex_group[i][0], convex_group[i][2] - convex_group[i][0], convex_list[i])
86 | len_pre = convex_group[i][2] - convex_group[i][1]
87 | pre_x = np.linspace(0, len_pre, len_pre + 1) * 2
88 | after_x = np.linspace(0, 2 * len_pre, 2 * len_pre + 1)
89 | print(convex_group[i])
90 |
91 | plot_peaks(np.array(y_list), indexes, mph=1, mpd=1.8, algorithm='scipy.signal.find_peaks')
92 | plot_peaks(np.array(inverse_y_list), inverse_indexes, mph=1, mpd=1.9, algorithm='scipy.signal.find_peaks')
93 | plt.show()
94 |
95 | indexes2 = eliminate_peaks(indexes, y_list, 10, 0.25)
96 | plot_peaks(np.array(y_list), indexes2, mph=1, mpd=1.9, algorithm='scipy.signal.find_peaks')
97 | plt.show()
98 |
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/eventdtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | from scipy.misc import *
8 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_fact_align, get_reverse_dict, get_SS2, calculate_event, get_link_graph, get_true_align
9 | from parameter_cal.utils import load_data, plot_warped_signals, cal_warped_signals
10 |
11 |
12 | def norm(x, y):
13 | #return math.fabs(x[1] - y[1])
14 | return math.fabs(x[1] - y[1])+math.fabs(x[2] - y[2])+math.fabs(x[3] - y[3])
15 |
16 |
17 | y_list = load_data('data/Beef_TRAIN')
18 | query, reference = cal_warped_signals(y_list)
19 |
20 | reference['upslope'] = 0
21 | reference['downslope'] = 0
22 |
23 | # plot warped signal
24 | xvals, yinterp = plot_warped_signals(reference, query)
25 |
26 |
27 | # calculate the corresponding point pair
28 | query.drop('shift', axis=1)
29 | query.drop('t', axis=1)
30 | query2 = pd.DataFrame(yinterp)
31 | query2['aligned_index'] = 0
32 | query2['t'] = query['t']
33 | query2.columns = ['q', 'aligned_index', 't']
34 | query2['upslope'] = 0
35 | query2['downslope'] = 0
36 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
37 | for i in range(len(query2) - 1):
38 | for j in range(len(query['t2']) - 1):
39 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
40 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
41 | query2.loc[i, 'aligned_index'] = j
42 | else:
43 | query2.loc[i, 'aligned_index'] = j + 1
44 |
45 | refer_peak_indexes = np.array([211])
46 | query_peak_indexes = np.array([201])
47 | calculate_event(refer_peak_indexes, reference, 1)
48 | calculate_event(query_peak_indexes, query2, 1)
49 |
50 |
51 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values, query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
52 | true_align_dict = get_true_align(query2)
53 | fact_dict = get_fact_align(path)
54 | get_link_graph(reference, query2, path, -3)
55 | reverse_dict = get_reverse_dict(path)
56 | print("path = " + str(len(path[0])))
57 | print('group = '+str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
58 | print("SS1 of dtw is " + str(get_W(path)))
59 | print("SS2 of dtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
60 |
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/original_eventdtw_downsample.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | import scipy.signal
8 | from scipy.misc import *
9 | from parameter_cal.utils import get_SS1, get_fact_align, get_reverse_dict, get_SS2, calculate_event, get_link_graph, load_data
10 | from parameter_cal.utils import plot_warped_signals, cal_warped_signals, draw_the_peaks, exp_decay
11 | import matplotlib.pyplot as plt
12 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
13 |
14 |
15 | def sigmoid0(x):
16 | return (4 * cf.warp_width) / (1 + math.exp(-x / cf.warp_width))
17 |
18 |
19 | sigmoid = np.vectorize(sigmoid0)
20 |
21 |
22 | def calculate_event(peak_indexes, df, time):
23 | slope_length = 20
24 | slope_weight = 1
25 | for peak_index in peak_indexes:
26 | for i in range(1, int(slope_length / time)):
27 | df.loc[peak_index - i, 'upslope'] = derivative(sigmoid, math.fabs(i * time), dx=1e-6) * slope_weight
28 | df.loc[peak_index + i, 'downslope'] = derivative(sigmoid, math.fabs(i * time), dx=1e-6) * slope_weight
29 | for peak_index in peak_indexes:
30 | df.loc[peak_index, 'upslope'] = 0
31 | df.loc[peak_index, 'downslope'] = 0
32 |
33 |
34 | def calculate_event0(peak_indexes, signal, time=1):
35 | slope_length = 20
36 | for peak_index in peak_indexes:
37 | center_time = signal.loc[peak_index, 't']
38 | signal.loc[peak_index, 'upslope'] = 1
39 | signal.loc[peak_index, 'downslope'] = 1
40 | for i in range(1, int(slope_length / time)):
41 | signal.loc[peak_index + i, 'downslope'] = exp_decay(
42 | math.fabs(signal.loc[peak_index + i, 't'] - center_time))
43 | signal.loc[peak_index - i, 'upslope'] = exp_decay(math.fabs(signal.loc[peak_index - i, 't'] - center_time))
44 |
45 |
46 | def get_matched_pairs(reference, query, refer_peaks, query_peaks, threshold=20):
47 | refer_len = len(refer_peaks)
48 | pairs = []
49 | for i in range(0, refer_len):
50 | refer_index = refer_peaks[i]
51 | refer_time = reference.loc[refer_index, 't']
52 | get = 0
53 | for index in query_peaks:
54 | query_time = query.loc[index, 't']
55 | if math.fabs(query_time - refer_time) > threshold:
56 | continue
57 | else:
58 | pairs.append([refer_index, index])
59 | get = 1
60 | break
61 | if get == 1:
62 | continue
63 | return pairs
64 |
65 |
66 | def norm(x, y):
67 | # return math.fabs(x[1] - y[1])
68 | return math.fabs(x[1] - y[1]) + math.fabs(x[2] - y[2]) + math.fabs(x[3] - y[3])
69 |
70 |
71 | # generate warped signal
72 | y_list = load_data('data/Beef_TRAIN')
73 | query, reference = cal_warped_signals(y_list)
74 |
75 | reference['upslope'] = 0
76 | reference['downslope'] = 0
77 |
78 | # plot warped signal
79 | # downsample times
80 | xvals, yinterp = plot_warped_signals(reference, query)
81 |
82 | # calculate the corresponding point pair
83 | query.drop('shift', axis=1)
84 | query.drop('t', axis=1)
85 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
86 | query2['close_index'] = 0
87 | query2['upslope'] = 0
88 | query2['downslope'] = 0
89 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
90 | group_num_dict = get_group_number(true_align_dict, query)
91 | plt.show()
92 |
93 | refer_peak_indexes = scipy.signal.find_peaks(y_list, height=np.mean(y_list), distance=20)
94 | query_peak_indexes = scipy.signal.find_peaks(query2.loc[:, 'q'], height=np.mean(query2.loc[:, 'q']), distance=20)
95 | pairs = get_matched_pairs(reference, query2, refer_peak_indexes[0], query_peak_indexes[0], 20)
96 | refer_indexes = []
97 | query_indexes = []
98 |
99 | for i in range(0, len(pairs)):
100 | refer_indexes.append(pairs[i][0])
101 | query_indexes.append(pairs[i][1])
102 |
103 | draw_the_peaks(reference, query2, refer_indexes, query_indexes, -3, 'Downsampled signal with peaks')
104 | calculate_event(refer_indexes, reference, 1)
105 | calculate_event(query_indexes, query2, cf.ds_time)
106 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q', 'upslope', 'downslope']].values,
107 | query2[['t', 'q', 'upslope', 'downslope']].values, dist=norm)
108 |
109 | get_link_graph(reference, query2, path, -3, 'Downsampled signal with EventDTW')
110 | fact_align_dict = get_fact_align(path)
111 | reverse_dict = get_reverse_dict(path)
112 | print("path = " + str(len(path[0])))
113 | print('group = ' + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
114 | print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
115 | print("SS2 of dtw is " + str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
116 |
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/parameter_cal_with_dDTW.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import numpy as np
4 | from parameter_cal import cf
5 | from dtw import dtw
6 | from scipy.misc import *
7 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_fact_align, get_SS2, get_reverse_dict, get_true_align, get_link_graph
8 | from parameter_cal.utils import plot_warped_signals, load_data, cal_warped_signals
9 | import matplotlib.pyplot as plt
10 |
11 |
12 | def slope_col(query):
13 | # calculate the slope of query
14 | query_last = len(query) - 1
15 | query['slope'] = 0
16 | query.loc[1, 'slope'] = ((query.loc[1, 'q'] - query.loc[0, 'q']) + ((query.loc[2 , 'q'] - query.loc[1, 'q']) / 2)) / 2
17 | query.loc[0, 'slope'] = query.loc[1, 'slope']
18 | for i in range(2, query_last - 1):
19 | query.loc[i , 'slope'] = ((query.loc[i, 'q'] - query.loc[i-1, 'q']) + ((query.loc[i+1, 'q'] - query.loc[i, 'q']) / 2)) / 2
20 | query.loc[query_last - 1, 'slope'] = ((query.loc[query_last - 1, 'q'] - query.loc[query_last - 2, 'q']) + ((query.loc[query_last, 'q'] - query.loc[query_last - 1, 'q']) / 2)) / 2
21 | query.loc[query_last, 'slope'] = query.loc[query_last - 1, 'slope']
22 |
23 |
24 | def norm(x, y):
25 | return math.fabs(x[1] - y[1])
26 |
27 |
28 | def gaussian_bump(x, a=1):
29 | return math.exp(1 / (pow((x / a), 2) - 1))
30 |
31 |
32 | # when x = 0, sigmoid's derivative value is 1/4a
33 | def sigmoid0(x):
34 | return (4 * cf.warp_width) / (1 + math.exp(-x / cf.warp_width))
35 |
36 |
37 | sigmoid = np.vectorize(sigmoid0)
38 |
39 | y_list = load_data('data/Beef_TRAIN', 1)
40 | query, reference = cal_warped_signals(y_list)
41 |
42 | # plot warped signal
43 | xvals, yinterp = plot_warped_signals(reference, query)
44 |
45 | # store the corresponding point pair
46 | query.drop('shift', axis=1)
47 | query.drop('t', axis=1)
48 | query2 = pd.DataFrame(yinterp)
49 | query2['aligned_index'] = 0
50 | query2['t'] = query['t']
51 | query2.columns = ['q', 'aligned_index', 't']
52 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
53 | for i in range(len(query2) - 1):
54 | for j in range(len(query['t2']) - 1):
55 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
56 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
57 | query2.loc[i, 'aligned_index'] = j
58 | else:
59 | query2.loc[i, 'aligned_index'] = j + 1
60 |
61 |
62 | slope_col(query2)
63 | slope_col(reference)
64 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'slope']].values, query2[['t', 'slope']].values, dist=norm)
65 | get_link_graph(reference, query2, path, -3)
66 | true_align_dict = get_true_align(query2)
67 | fact_dict = get_fact_align(path)
68 | reverse_dict = get_reverse_dict(path)
69 | print("error rate of dtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
70 | print("W of ddtw is " + str(get_W(path)))
71 | print("SS2 of ddtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
72 |
--------------------------------------------------------------------------------
/Signal-Alignment/parameter_cal/parameter_cal_with_dtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from parameter_cal import cf
6 | from parameter_cal.utils import get_k_accuracy_same, get_W, get_SS2, get_fact_align, get_reverse_dict, get_true_align, get_link_graph, load_data
7 | from parameter_cal.utils import plot_warped_signals, cal_warped_signals
8 | from dtw import dtw
9 | from scipy.misc import *
10 | import matplotlib.pyplot as plt
11 |
12 |
13 | def norm(x, y):
14 | return math.fabs(x[1] - y[1])
15 |
16 |
17 | y_list = load_data(True)
18 | query, reference = cal_warped_signals(y_list)
19 |
20 |
21 | # plot warped signal
22 | xvals, yinterp = plot_warped_signals(reference, query)
23 |
24 |
25 | # store the corresponding point pair
26 | query.drop('shift', axis=1)
27 | query.drop('t', axis=1)
28 | query2 = pd.DataFrame(yinterp)
29 | query2['aligned_index'] = 0
30 | query2['t'] = query['t']
31 | query2.columns = ['q', 'aligned_index', 't']
32 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
33 | for i in range(len(query2) - 1):
34 | for j in range(len(query['t2']) - 1):
35 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
36 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
37 | query2.loc[i, 'aligned_index'] = j
38 | else:
39 | query2.loc[i, 'aligned_index'] = j + 1
40 |
41 | d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q']].values, query2[['t', 'q']].values, dist=norm)
42 | get_link_graph(reference, query2, path, -3)
43 | true_align_dict = get_true_align(query2)
44 | fact_dict = get_fact_align(path)
45 | reverse_dict = get_reverse_dict(path)
46 | print("error rate of dtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
47 | print("W of dtw is " + str(get_W(path)))
48 | print("SS2 of dtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/__pycache__/config.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/sdtw/__pycache__/config.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/__pycache__/utils.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/Signal-Alignment/sdtw/__pycache__/utils.cpython-37.pyc
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/config.py:
--------------------------------------------------------------------------------
1 | nBlocks = 2
2 | nbins = 8
3 | dx_scale = 0.1
4 | sub_len = 19
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/downsample_modi_shapedtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from scipy import stats
6 | from parameter_cal import cf
7 | from dtw import dtw
8 | from scipy.misc import *
9 | from sdtw.config import sub_len, nBlocks
10 | from sdtw.utils import cal_descriptor, samplingSequences, norm
11 | from parameter_cal.utils import get_fact_align, get_reverse_dict, get_SS2, get_SS1, get_link_graph
12 | from parameter_cal.cf import ds_time
13 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
14 | import matplotlib.pyplot as plt
15 |
16 |
17 | # when x = 0, sigmoid's derivative value is 1/4a
18 | def sigmoid0(x):
19 | return (4 * 40) / (1 + math.exp(-x / 40))
20 |
21 |
22 | def gaussian_bump(x, a=1):
23 | return math.exp(1 / (pow((x / a), 2) - 1))
24 |
25 |
26 | sigmoid = np.vectorize(sigmoid0)
27 |
28 | # generate warped signal
29 | y = linecache.getline('data/Beef_TRAIN', 1)
30 | y_list = y.split(',')
31 | # delete the index
32 | y_list.pop(0)
33 | y_list = [float(item) for item in y_list]
34 | reference = pd.DataFrame(y_list)
35 | reference['t'] = [i for i in range(0, len(reference))]
36 | reference.columns = ['q', 't']
37 | anchor_index = 220
38 | anchor_shift = 10
39 | reference['shift'] = [derivative(sigmoid, math.fabs(anchor_index - i), dx=1e-6) * anchor_shift for i in reference['t']]
40 | query = pd.DataFrame(reference)
41 | query.columns = ['q', 't', 'shift']
42 | query['t2'] = 0.1
43 | temp = []
44 | for i, j in zip(query['t'].values, query['shift'].values):
45 | temp.append(i - j)
46 | query['t2'] = temp
47 | # add gaussian bump
48 | range_of_gaussian = 40
49 | height_of_gaussian = 1.2
50 | temp = query[(query['t'] < anchor_index + 40) & (query['t'] > anchor_index - 40)].index
51 | for i in temp:
52 | query.loc[i, 'q'] = query.loc[i, 'q'] + height_of_gaussian * gaussian_bump(i - anchor_index, range_of_gaussian)
53 |
54 | # plot warped signal
55 | _, ax = plt.subplots(1, 1, figsize=(20, 10))
56 | ax.scatter(x=query['t'], y=reference['q'], c='b', marker='.', label='before warp')
57 | ax.scatter(x=query['t2'], y=query['q'], c='r', marker='.', label='after warp')
58 | xvals = np.linspace(0, len(query['t']) - 1, math.floor(len(query['t']) / cf.ds_time))
59 | x = query['t2']
60 | y = query['q']
61 | yinterp = np.array(np.interp(xvals, x, y))
62 | xvals = np.array(xvals)
63 | ax.scatter(x=xvals, y=yinterp, marker='.', c='g', label='after interp')
64 | ax.legend(fontsize='30')
65 |
66 | # normalize the signal
67 | reference_norm = stats.zscore(reference['q'])
68 | yinterp_norm = stats.zscore(yinterp)
69 |
70 | # store the corresponding point pair
71 | query.drop(['t','shift'], axis=1)
72 | query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
73 | query2['close_index'] = 0
74 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
75 | group_num_dict = get_group_number(true_align_dict, query)
76 |
77 |
78 | refer_subsequences = samplingSequences(reference_norm, sub_len)
79 | query_subsequences = samplingSequences(yinterp_norm, int(sub_len/cf.ds_time))
80 | refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
81 | query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
82 | refer_nsubsequences = len(refer_subsequences)
83 | query_nsubsequences = len(query_subsequences)
84 |
85 | for i in range(refer_nsubsequences):
86 | sub_seq = refer_subsequences[i]
87 | refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)
88 |
89 | for i in range(query_nsubsequences):
90 | sub_seq = query_subsequences[i]
91 | query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len/cf.ds_time))
92 |
93 | d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
94 | get_link_graph(reference, query2, path, -3, 'downsampled shapedtw')
95 | fact_align_dict = get_fact_align(path)
96 | reverse_dict = get_reverse_dict(path)
97 | print("error rate of shapedtw is " + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
98 | print("SS1 of shapedtw is " + str(get_SS1(path, cf.ds_time)))
99 | print("SS2 of shapedtw is " + str(get_SS2(fact_align_dict, reverse_dict, ds_time)))
100 |
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/parameter_cal_with_shapedtw.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import numpy as np
4 | from scipy import stats
5 | from parameter_cal import cf
6 | from dtw import dtw
7 | from scipy.misc import *
8 | from sdtw.config import sub_len, nBlocks
9 | from sdtw.utils import norm, cal_refer_query_descriptor
10 | from parameter_cal.utils import get_fact_align, get_reverse_dict, get_k_accuracy_same, get_W, get_SS2, get_true_align, get_link_graph
11 | from parameter_cal.utils import load_data, plot_warped_signals, cal_warped_signals
12 | import matplotlib.pyplot as plt
13 |
14 |
15 | y_list = load_data(True)
16 | query, reference = cal_warped_signals(y_list)
17 |
18 | # plot warped signal
19 | xvals, yinterp = plot_warped_signals(reference, query)
20 |
21 | # normalize the signal
22 | reference_norm = stats.zscore(reference['q'])
23 | yinterp_norm = stats.zscore(yinterp)
24 |
25 | # store the corresponding point pair
26 | query.drop('shift', axis=1)
27 | query.drop('t', axis=1)
28 | query2 = pd.DataFrame(yinterp)
29 | query2['aligned_index'] = 0
30 | query2['t'] = query['t']
31 | query2.columns = ['q', 'aligned_index', 't']
32 | query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
33 | for i in range(len(query2) - 1):
34 | for j in range(len(query['t2']) - 1):
35 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
36 | if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
37 | query2.loc[i, 'aligned_index'] = j
38 | else:
39 | query2.loc[i, 'aligned_index'] = j + 1
40 |
41 |
42 | if sub_len%2 == 0:
43 | raise Exception("Sub_len must be odd number!")
44 |
45 | refer_descriptors, query_descriptors = cal_refer_query_descriptor(reference_norm, yinterp_norm, sub_len)
46 |
47 |
48 | d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
49 | get_link_graph(reference, query, path, -3, 'shapedtw without downsample')
50 | true_align_dict = get_true_align(query2)
51 | fact_dict = get_fact_align(path)
52 | reverse_dict = get_reverse_dict(path)
53 | print("error rate of shapedtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
54 | print("W of shapedtw is " + str(get_W(path)))
55 | print("SS2 of shapedtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/test.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import math
3 | import linecache
4 | import numpy as np
5 | from scipy import stats
6 | from parameter_cal import cf
7 | from dtw import dtw
8 | from scipy.misc import *
9 | from sdtw.config import sub_len, nBlocks
10 | from sdtw.utils import cal_descriptor, samplingSequences, norm, get_link_graph
11 | from parameter_cal.utils import get_fact_align, get_reverse_dict, get_SS2, get_SS1
12 | from parameter_cal.cf import ds_time
13 | from downsample.utils import get_true_aligned, get_group_number, get_k_accuracy
14 | import matplotlib.pyplot as plt
15 |
16 |
17 | # when x = 0, sigmoid's derivative value is 1/4a
18 | def sigmoid0(x):
19 | return (4 * cf.warp_width) / (1 + math.exp(-x / cf.warp_width))
20 |
21 |
22 | def gaussian_bump(x, a=1):
23 | return math.exp(1 / (pow((x / a), 2) - 1))
24 |
25 |
26 | sigmoid = np.vectorize(sigmoid0)
27 |
28 | # generate warped signal
29 | y = linecache.getline('data/Beef_TRAIN', 1)
30 | y_list = y.split(',')
31 | # delete the index
32 | y_list.pop(0)
33 | y_list = [float(item) for item in y_list]
34 | reference = pd.DataFrame(y_list)
35 | reference['t'] = [i for i in range(0, len(reference))]
36 | reference.columns = ['q', 't']
37 | anchor_index = 220
38 | anchor_shift = 10
39 | reference['shift'] = [derivative(sigmoid, math.fabs(anchor_index - i), dx=1e-6) * anchor_shift for i in reference['t']]
40 | query = pd.DataFrame(reference)
41 | query.columns = ['q', 't', 'shift']
42 | query['t2'] = 0.1
43 | temp = []
44 | for i, j in zip(query['t'].values, query['shift'].values):
45 | temp.append(i - j)
46 | query['t2'] = temp
47 | # add gaussian bump
48 | range_of_gaussian = 40
49 | height_of_gaussian = 1.2
50 | temp = query[(query['t'] < anchor_index + 40) & (query['t'] > anchor_index - 40)].index
51 | for i in temp:
52 | query.loc[i, 'q'] = query.loc[i, 'q'] + height_of_gaussian * gaussian_bump(i - anchor_index, range_of_gaussian)
53 |
54 | # plot warped signal
55 | _, ax = plt.subplots(1, 1, figsize=(20, 10))
56 | ax.scatter(x=query['t'], y=reference['q'], c='b', marker='.', label='before warp')
57 | ax.scatter(x=query['t2'], y=query['q'], c='r', marker='.', label='after warp')
58 | xvals = np.linspace(0, len(query['t']) - 1, math.floor(len(query['t']) / cf.ds_time))
59 | x = query['t2']
60 | y = query['q']
61 | yinterp = np.array(np.interp(xvals, x, y))
62 | xvals = np.array(xvals)
63 | ax.scatter(x=xvals, y=yinterp, marker='.', c='g', label='after interp')
64 | ax.legend(fontsize='30')
65 |
66 | # normalize the signal
67 | reference_norm = stats.zscore(reference['q'])
68 | yinterp_norm = stats.zscore(yinterp)
69 |
70 | # store the corresponding point pair
71 | query.drop('shift', axis=1)
72 | query.drop('t', axis=1)
73 | query2 = pd.DataFrame({'t': xvals, 'q2': yinterp})
74 | query2['close_index'] = 0
75 | true_align_dict = get_true_aligned(cf.ds_time, query, query2)
76 | group_num_dict = get_group_number(true_align_dict, query)
77 | query2.loc[len(query2) - 1, 'close_index'] = len(query) - 1
78 | for i in range(len(query2) - 1):
79 | for j in range(len(query['t2']) - 1):
80 | if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
81 | if abs(query2['q2'][i] - query['q'][j]) < abs(query2['q2'][i] - query['q'][j + 1]):
82 | query2.loc[i, 'close_index'] = j
83 | else:
84 | query2.loc[i, 'close_index'] = j + 1
85 |
86 | if sub_len % 2 == 0:
87 | raise Exception("Sub_len must be odd number!")
88 |
89 | refer_subsequences = samplingSequences(reference_norm, sub_len)
90 | query_subsequences = samplingSequences(yinterp_norm, int(sub_len/cf.ds_time))
91 | refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
92 | query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
93 | refer_nsubsequences = len(refer_subsequences)
94 | query_nsubsequences = len(query_subsequences)
95 |
96 | for i in range(refer_nsubsequences):
97 | sub_seq = refer_subsequences[i]
98 | refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)
99 |
100 | for i in range(query_nsubsequences):
101 | sub_seq = query_subsequences[i]
102 | query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len/cf.ds_time))
103 |
104 | d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
105 | query2.columns = ['t2', 'q', 'close_index'] # adapt to the get_link_graph
106 | get_link_graph(reference, query2, path, -3, 'downsampled shapedtw')
107 | fact_align_dict = get_fact_align(path)
108 | reverse_dict = get_reverse_dict(path)
109 | print("error rate of shapedtw is " + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
110 | print("SS1 of shapedtw is " + str(get_SS1(path, cf.ds_time)))
111 | print("SS2 of shapedtw is " + str(get_SS2(fact_align_dict, reverse_dict, ds_time)))
112 |
--------------------------------------------------------------------------------
/Signal-Alignment/sdtw/utils.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import math
3 | from sdtw.config import nBlocks, nbins, dx_scale
4 | import matplotlib.pyplot as plt
5 |
6 |
7 | def whichInterval(angles, ang):
8 | if ang < angles[0]:
9 | return 0
10 | if ang >= angles[-1]:
11 | return len(angles) - 2
12 | for i in range(len(angles)):
13 | if angles[i] <= ang < angles[i + 1]:
14 | return i
15 |
16 |
17 | # the number of bins is 8
18 | angles = np.linspace(-math.pi / 2, math.pi / 2, nbins + 1)
19 | deg_angles = np.linspace(-180 / 2, 180 / 2, nbins + 1)
20 | center_angles = np.array([])
21 | for i in range(len(deg_angles) - 1):
22 | center_angles = np.append(center_angles, (angles[i] + angles[i + 1]) / 2)
23 | deg_center_angles = np.append(center_angles, (deg_angles[i] + deg_angles[i + 1]) / 2)
24 |
25 |
26 | def cal_descriptor(y_list, sub_len):
27 | y_list = np.insert(y_list, 0, y_list[0])
28 | y_list = np.append(y_list, y_list[-1])
29 | sCell = math.ceil(sub_len / 2) - 1
30 | idx_start = 0
31 |
32 | descriptor = np.zeros((nBlocks, nbins))
33 |
34 | for i in range(nBlocks):
35 | for j in range(sCell):
36 | idx = i * sCell + j
37 | cidx = idx_start + idx
38 | # centered gradient
39 | sidx = cidx - 1
40 | eidx = cidx + 1
41 | if (sidx < 0) or (eidx > sub_len - 1):
42 | continue
43 | dx = 2 * dx_scale
44 | dy = y_list[eidx] - y_list[sidx]
45 | ang = math.atan2(dy, dx)
46 | mag = dy / dx
47 |
48 | n = whichInterval(angles, ang)
49 | if n == 0 and ang < center_angles[0]:
50 | descriptor[i, n] = descriptor[i, n] + math.fabs(mag)
51 | elif n == len(center_angles) - 1 and ang >= center_angles[len(center_angles) - 1]:
52 | descriptor[i, n] = descriptor[i, n] + math.fabs(mag)
53 | else:
54 | if math.fabs(angles[n] - ang) > math.fabs(angles[n + 1] - ang):
55 | ang1 = center_angles[n]
56 | ang2 = center_angles[n + 1]
57 |
58 | descriptor[i, n] = descriptor[i, n] + math.fabs(mag) * math.cos(ang1 - ang)
59 | descriptor[i, n + 1] = descriptor[i, n + 1] + math.fabs(mag) * math.cos(ang2 - ang)
60 | else:
61 | ang1 = center_angles[n - 1]
62 | ang2 = center_angles[n]
63 |
64 | descriptor[i, n - 1] = descriptor[i, n - 1] + math.fabs(mag) * math.cos(ang1 - ang)
65 | descriptor[i, n] = descriptor[i, n] + math.fabs(mag) * math.cos(ang2 - ang)
66 |
67 | return descriptor.reshape(descriptor.size)
68 |
69 |
70 | def samplingSequences(sequences, sub_len):
71 | info = np.zeros((len(sequences), sub_len))
72 | original_len = len(sequences)
73 | if sub_len % 2 == 0:
74 | sequences = np.insert(sequences, 0, np.ones((math.floor(sub_len / 2) - 1,)) * sequences[0])
75 | sequences = np.append(sequences, np.ones((math.floor(sub_len / 2) - 1,)) * sequences[-1])
76 | stidx = math.floor(sub_len / 2) - 1
77 | edidx = len(sequences) - math.floor(sub_len / 2)
78 | # there is a difference between odd and equal
79 | for i in range(stidx, edidx):
80 | infoidx = i - math.floor(sub_len / 2) + 1
81 | info[infoidx] = sequences[i - math.floor(sub_len / 2) + 1:i + math.floor(sub_len / 2) + 1]
82 | else:
83 | sequences = np.insert(sequences, 0, np.ones((math.floor(sub_len / 2),)) * sequences[0])
84 | sequences = np.append(sequences, np.ones((math.floor(sub_len / 2),)) * sequences[-1])
85 | stidx = math.floor(sub_len / 2)
86 | edidx = len(sequences) - math.floor(sub_len / 2) - 1
87 | for i in range(stidx, edidx + 1):
88 | infoidx = i - math.floor(sub_len / 2)
89 | info[infoidx] = sequences[i - math.floor(sub_len / 2):i + math.floor(sub_len / 2) + 1]
90 |
91 | return info
92 |
93 |
94 | # how to measure the distance
95 | def norm(reference, query):
96 | return np.linalg.norm(reference - query)
97 |
98 |
99 | def cal_refer_query_descriptor(reference_norm, yinterp_norm, sub_len):
100 | refer_subsequences = samplingSequences(reference_norm, sub_len)
101 | query_subsequences = samplingSequences(yinterp_norm, sub_len)
102 | refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
103 | query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
104 | refer_nsubsequences = len(refer_subsequences)
105 | query_nsubsequences = len(query_subsequences)
106 |
107 | for i in range(refer_nsubsequences):
108 | sub_seq = refer_subsequences[i]
109 | refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)
110 |
111 | for i in range(query_nsubsequences):
112 | sub_seq = query_subsequences[i]
113 | query_descriptors[i] = cal_descriptor(sub_seq, sub_len)
114 |
115 | return refer_descriptors, query_descriptors
116 |
--------------------------------------------------------------------------------
/hpc:group:dunnlab:yj167:tes.textClipping:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigitalBiomarkerDiscoveryPipeline/Pre-process/51b24e775b40c6a1b75bff5eef684f3615e823d7/hpc:group:dunnlab:yj167:tes.textClipping
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | pandas
2 | numpy
3 | matplotlib
4 | seaborn
5 | datetime
6 | pytz
7 | rowingdata
8 | mne
9 | os-sys
10 | npm
11 | regex
--------------------------------------------------------------------------------