Fast Dynamic Time Warping (DTW) is a modified version of DTW that is designed to speed up the computation process when dealing with large time series. It achieves this by recursively reducing the size of the time series and calculating the DTW path on these reduced versions. However, in doing so, it may sacrifice some accuracy compared to the actual DTW distance.
------

set schema DM_PAL;

drop table PAL_FAST_DTW_DATA_TAB;
create column table PAL_FAST_DTW_DATA_TAB (
	"ID" nvarchar(100),
	"TIMESTAMP" integer,
	"ATTR1" integer,
	"ATTR2" double
);

drop table PAL_PARAMETER_TAB;
create column table PAL_PARAMETER_TAB (
	"PARAM_NAME" nvarchar (256),
	"INT_VALUE" integer,
	"DOUBLE_VALUE" double,
	"STRING_VALUE" nvarchar (1000)
);

drop table PAL_FAST_DTW_RES_TAB;
create column table PAL_FAST_DTW_RES_TAB (
	"LEFT_ID" nvarchar(100),
	"RIGHT_ID" nvarchar(100),
	"DISTANCE" double
);

drop table PAL_FAST_DTW_ALIGN_TAB;
create column table PAL_FAST_DTW_ALIGN_TAB (
	"LEFT_ID" nvarchar(100),
	"RIGHT_ID" nvarchar(100),
	"LEFT_INDEX" integer,
    "RIGHT_INDEX" integer
);

drop table PAL_FAST_DTW_STAT_TAB;
create column table PAL_FAST_DTW_STAT_TAB (
	"STAT_NAME" nvarchar(256),
	"STAT_VALUE" nvarchar(1000)
);

truncate table PAL_FAST_DTW_DATA_TAB;
insert into PAL_FAST_DTW_DATA_TAB values (1, 1, 1, 5.2);
insert into PAL_FAST_DTW_DATA_TAB values (1, 2, 2, 5.1);
insert into PAL_FAST_DTW_DATA_TAB values (1, 3, 3, 2.0);
insert into PAL_FAST_DTW_DATA_TAB values (1, 4, 4, 0.3);
insert into PAL_FAST_DTW_DATA_TAB values (1, 5, 5, 1.2);
insert into PAL_FAST_DTW_DATA_TAB values (1, 6, 6, 7.7);
insert into PAL_FAST_DTW_DATA_TAB values (1, 7, 7, 0.0);
insert into PAL_FAST_DTW_DATA_TAB values (1, 8, 8, 1.1);
insert into PAL_FAST_DTW_DATA_TAB values (1, 9, 9, 3.2);
insert into PAL_FAST_DTW_DATA_TAB values (1, 10, 10, 2.3);

insert into PAL_FAST_DTW_DATA_TAB values (2, 1, 7, 2.0);
insert into PAL_FAST_DTW_DATA_TAB values (2, 2, 6, 1.4);
insert into PAL_FAST_DTW_DATA_TAB values (2, 3, 1, 0.9);
insert into PAL_FAST_DTW_DATA_TAB values (2, 4, 3, 1.2);
insert into PAL_FAST_DTW_DATA_TAB values (2, 5, 2, 10.2);
insert into PAL_FAST_DTW_DATA_TAB values (2, 6, 5, 2.3);
insert into PAL_FAST_DTW_DATA_TAB values (2, 7, 4, 4.5);
insert into PAL_FAST_DTW_DATA_TAB values (2, 8, 3, 4.6);
insert into PAL_FAST_DTW_DATA_TAB values (2, 9, 3, 3.5);

insert into PAL_FAST_DTW_DATA_TAB values (3, 1, 10, 1.0);
insert into PAL_FAST_DTW_DATA_TAB values (3, 2, 5, 2.0);
insert into PAL_FAST_DTW_DATA_TAB values (3, 3, 2, 3.0);
insert into PAL_FAST_DTW_DATA_TAB values (3, 4, 8, 1.4);
insert into PAL_FAST_DTW_DATA_TAB values (3, 5, 1, 10.8);
insert into PAL_FAST_DTW_DATA_TAB values (3, 6, 5, 7.7);
insert into PAL_FAST_DTW_DATA_TAB values (3, 7, 5, 6.3);
insert into PAL_FAST_DTW_DATA_TAB values (3, 8, 12, 2.4);
insert into PAL_FAST_DTW_DATA_TAB values (3, 9, 20, 9.4);
insert into PAL_FAST_DTW_DATA_TAB values (3, 10, 4, 0.5);
insert into PAL_FAST_DTW_DATA_TAB values (3, 11, 6, 2.2);

truncate table PAL_PARAMETER_TAB;
insert into PAL_PARAMETER_TAB values ('RADIUS', 5, null, null);
insert into PAL_PARAMETER_TAB values ('THREAD_RATIO', null, 1, null);
insert into PAL_PARAMETER_TAB values ('DISTANCE_METHOD', 2, null, null);
insert into PAL_PARAMETER_TAB values ('SAVE_ALIGNMENT', 1, null, null);

call _SYS_AFL.PAL_FAST_DTW(PAL_FAST_DTW_DATA_TAB, PAL_PARAMETER_TAB, ?, ?, ?);

