Commit 9dba0c5c authored by paugier's avatar paugier
Browse files

Clean up dtw_cort_dist

parent eb506e6c
......@@ -5,6 +5,7 @@
*.so
*.o
*.pstats
*.mod
_build
build
......@@ -24,4 +25,6 @@ ipynb/index.rst
ipynb/index.html
pyfiles/dtw_cort_dist/V5_cython/*.c
pyfiles/dtw_cort_dist/V5_cython/*.html
\ No newline at end of file
pyfiles/dtw_cort_dist/V5_cython/*.html
**/V*/res_cort.npy
**/V*/res_dtw.npy
\ No newline at end of file
......@@ -19,8 +19,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......@@ -39,7 +38,6 @@ def DTWDistance(s1, s2):
_dtw_mat[0, 0] = abs(s1[0] - s2[0])
# two special cases : filling first row and columns
for j in range(1, len_s2):
dist = abs(s1[0] - s2[j])
_dtw_mat[0, j] = dist + _dtw_mat[0, j - 1]
......
......@@ -5,7 +5,6 @@ from runpy import run_path
from pathlib import Path
import numpy as np
import math
util = run_path(Path(__file__).absolute().parent.parent / "util.py")
......@@ -20,8 +19,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......@@ -68,14 +66,12 @@ def cort(s1, s2):
:rtype: float64
"""
slope_1 = s1[1:] - s1[:-1]
slope_2 = s2[1:] - s2[:-1]
num = np.sum(slope_1 * slope_2)
sum_square_x = np.sum(slope_1 * slope_1)
sum_square_y = np.sum(slope_2 * slope_2)
return num / (math.sqrt(sum_square_x * sum_square_y))
return num / (np.sqrt(sum_square_x * sum_square_y))
def compute(series, nb_series):
......
......@@ -30,8 +30,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......
......@@ -27,8 +27,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......
#!/usr/bin/python3
#!/usr/bin/env python3
import numpy as np
import sysconfig
......@@ -25,8 +25,11 @@ def serie_pair_index_generator(number):
:returns: pairs (lower, greater)
:rtype: a generator
"""
return ((_idx_greater, _idx_lower) for _idx_greater in range(number)
for _idx_lower in range(number) if _idx_lower < _idx_greater)
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(_idx_greater)
)
def cDTW(serie_a, serie_b):
......@@ -50,6 +53,7 @@ def cort(serie_a, serie_b):
ret = dllib.cort(a_ptr, b_ptr, len(serie_a))
return ret
def compute(series, nb_series):
gen = serie_pair_index_generator(nb_series)
......
......@@ -10,6 +10,7 @@ from dtw_cort import cort, DTWDistance
util = run_path(Path(__file__).absolute().parent.parent / "util.py")
def serie_pair_index_generator(number):
""" generator for pair index (i, j) such that i < j < number
......@@ -20,8 +21,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......
all:
transonic dtw_cort_dist_mat.py
transonic dtw_cort_dist_mat.py -pf "-march=native -O3 -DUSE_XSIMD"
clean:
rm -rf __pythran__
\ No newline at end of file
......@@ -21,8 +21,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......@@ -62,23 +61,19 @@ def DTWDistance(s1, s2):
def cort(s1, s2):
""" Computes the cort between serie one and two (assuming they have the same length)
""" Computes the cort between series one and two (assuming they have the same length)
:param s1: the first serie (or any iterable over floats64)
:param s2: the second serie (or any iterable over floats64)
:param s1: the first series (or any iterable over floats64)
:param s2: the second series (or any iterable over floats64)
:returns: the cort distance
:rtype: float64
"""
num = 0.0
sum_square_x = 0.0
sum_square_y = 0.0
for t in range(len(s1) - 1):
slope_1 = s1[t + 1] - s1[t]
slope_2 = s2[t + 1] - s2[t]
num += slope_1 * slope_2
sum_square_x += slope_1 * slope_1
sum_square_y += slope_2 * slope_2
slope_1 = s1[1:] - s1[:-1]
slope_2 = s2[1:] - s2[:-1]
num = np.sum(slope_1 * slope_2)
sum_square_x = np.sum(slope_1 * slope_1)
sum_square_y = np.sum(slope_2 * slope_2)
return num / (np.sqrt(sum_square_x * sum_square_y))
......
......@@ -22,8 +22,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......@@ -63,23 +62,19 @@ def DTWDistance(s1, s2):
def cort(s1, s2):
""" Computes the cort between serie one and two (assuming they have the same length)
""" Computes the cort between series one and two (assuming they have the same length)
:param s1: the first serie (or any iterable over floats64)
:param s2: the second serie (or any iterable over floats64)
:param s1: the first series (or any iterable over floats64)
:param s2: the second series (or any iterable over floats64)
:returns: the cort distance
:rtype: float64
"""
num = 0.0
sum_square_x = 0.0
sum_square_y = 0.0
for t in range(len(s1) - 1):
slope_1 = s1[t + 1] - s1[t]
slope_2 = s2[t + 1] - s2[t]
num += slope_1 * slope_2
sum_square_x += slope_1 * slope_1
sum_square_y += slope_2 * slope_2
slope_1 = s1[1:] - s1[:-1]
slope_2 = s2[1:] - s2[:-1]
num = np.sum(slope_1 * slope_2)
sum_square_x = np.sum(slope_1 * slope_1)
sum_square_y = np.sum(slope_2 * slope_2)
return num / (np.sqrt(sum_square_x * sum_square_y))
......
all:
pythran kernels_pythran.py
pythran kernels_pythran.py -march=native -O3 -DUSE_XSIMD
clean:
rm -rf *.so
\ No newline at end of file
......@@ -6,8 +6,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if (_idx_lower < _idx_greater)
for _idx_lower in range(_idx_greater)
)
......@@ -37,17 +36,20 @@ def DTWDistance(s1, s2):
def cort(s1, s2):
" Computes the cort between serie one and two (assuming they have the same length)\n\n :param s1: the first serie (or any iterable over floats64)\n :param s2: the second serie (or any iterable over floats64)\n :returns: the cort distance\n :rtype: float64\n\n "
num = 0.0
sum_square_x = 0.0
sum_square_y = 0.0
for t in range((len(s1) - 1)):
slope_1 = s1[(t + 1)] - s1[t]
slope_2 = s2[(t + 1)] - s2[t]
num += slope_1 * slope_2
sum_square_x += slope_1 * slope_1
sum_square_y += slope_2 * slope_2
return num / np.sqrt((sum_square_x * sum_square_y))
""" Computes the cort between series one and two (assuming they have the same length)
:param s1: the first series (or any iterable over floats64)
:param s2: the second series (or any iterable over floats64)
:returns: the cort distance
:rtype: float64
"""
slope_1 = s1[1:] - s1[:-1]
slope_2 = s2[1:] - s2[:-1]
num = np.sum(slope_1 * slope_2)
sum_square_x = np.sum(slope_1 * slope_1)
sum_square_y = np.sum(slope_2 * slope_2)
return num / (np.sqrt(sum_square_x * sum_square_y))
# pythran export compute(float64[:, :], int)
......
......@@ -21,8 +21,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......
......@@ -20,8 +20,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......@@ -36,6 +35,7 @@ def DTWDistance(s1, s2):
dtw_result = dtw_cort.dtwdistance(s1, s2)
return dtw_result
def cort(s1, s2):
""" Computes the cort between serie one and two (assuming they have the same length)
......
......@@ -17,8 +17,7 @@ def serie_pair_index_generator(number):
return (
(_idx_greater, _idx_lower)
for _idx_greater in range(number)
for _idx_lower in range(number)
if _idx_lower < _idx_greater
for _idx_lower in range(_idx_greater)
)
......
......@@ -17,6 +17,7 @@ cffi
cython
numba
pythran
xsimd
transonic
# parallel
mpi4py
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment