Commit 457d68e0 authored by Franck Thollard's avatar Franck Thollard
Browse files

V3 resurection from broken

parent d1444ff4
all:
python3 setup.py develop
clean:
rm -f cdtw.*.so
rm -rf build dtw_cort_dist_mat.egg-info
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <float.h> /* for max_float */
#include "cdtw.h"
double min3(const double x, const double y, const double z){
if (x < y)
if (x < z) return x;
if (y < z) return y;
return z;
}
/*
Returns the minimum-distance warp path
between multivariate time series x and y.
*/
double dtw(double* x, double* y, int size_x, int size_y){
int i, j;
double* temp;
double *costP = malloc(size_x*sizeof(double));
if (! costP) return -1;
double *costC = malloc(size_x*sizeof(double));
if (! costC){
free(costP);
return -1; /* TODO: better handling of the error */
}
costP[0] = fabs(x[0] - y[0]);
for (i=1; i < size_x; i++){
costP[i] = fabs(x[i] - y[0]) + costP[i-1];
}
for (j=1; j< size_y; j++){
costC[0] = costP[0] + fabs(x[0] - y[j]);
for (i=1; i < size_x; i++){
costC[i] = min3(costC[i-1], costP[i-1], costP[i]) + fabs(x[i] - y[j]);
}
temp = costP;
costP = costC;
costC = temp;
}
/* result is read in costP because switching between costP and costC is done */
double ret = costP[size_x-1];
free(costP);
free(costC);
return ret;
}
double cort(double *x, double *y, int size){
int t;
double slopex, slopey;
double num;
double sumSquareXslope, sumSquareYslope;
num = sumSquareXslope = sumSquareYslope = 0.0;
for (t = 0; t < size-1; t++){
slopex = x[t+1] - x[t];
slopey = y[t+1] - y[t];
num += slopex * slopey;
sumSquareXslope += slopex * slopex;
sumSquareYslope += slopey * slopey;
}
return num/sqrt(sumSquareXslope*sumSquareYslope);
}
double dtw(double* x, double* y, int size_x, int size_y);
double cort(double *x, double *y, int size);
from setuptools import setup, Extension
version = "0.1"
module_distance = Extension(
name="cdtw",
sources=["cdtw.c"],
extra_compile_args=["-O3", "-mavx2"],
extra_link_args=["-O3"],
)
setup(
name="dtw_cort_dist_mat",
version=version,
description="data scientist tool for time series",
long_description="data scientist tool for time series",
classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
author="IKATS project",
author_email="Franck.Thollard@imag.fr",
url="http://ikats.imag.fr",
license="GPL",
include_package_data=True,
zip_safe=False,
install_requires=["cffi", "numpy", "setuptools"],
entry_points="",
ext_modules=[module_distance],
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment