Skip to content

Commit 9b4cf54

Browse files
Fixed #26 Use less-aggressive planning flag as default (#27)
* less intensive fft planning as default * use multiply param out to save result * add matlab sdp code * minor improvement in comment * minor changes
1 parent 17b671b commit 9b4cf54

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

matlab_sdp.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
% This function computes the sliding dot product between
2+
% a query Q and a time series T using the FFT method.
3+
4+
% See TABLE I (old) here: https://www.cs.ucr.edu/~eamonn/PID4481997_extend_Matrix%20Profile_I.pdf
5+
% See MASS_V2 here: https://www.cs.unm.edu/~mueen/FastestSimilaritySearch.html
6+
% MASS_V2 is used in [DAMP_2_0.m](https://drive.google.com/file/d/1EPDhFXQ2goTJ5m_x1S84-KNpQFsRNVmf/view?usp=sharing)
7+
8+
function [z] = fft_sdp(Q, T)
9+
% Input:
10+
% Q - query vector
11+
% T - time series vector
12+
% Output:
13+
% z - sliding dot product of Q and T
14+
15+
m = length(Q);
16+
n = length(T);
17+
18+
Q = Q(end:-1:1); % Reverse the query
19+
Q(m+1:n) = 0; % Append zeros
20+
21+
X = fft(T);
22+
Y = fft(Q);
23+
Z = X.*Y;
24+
z = ifft(Z);
25+
z = z(m:n);
26+
27+
end

sdp/pyfftw_sdp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, max_n=2**20):
2121
self.rfft_objects = {}
2222
self.irfft_objects = {}
2323

24-
def __call__(self, Q, T, n_threads=1, planning_flag="FFTW_MEASURE"):
24+
def __call__(self, Q, T, n_threads=1, planning_flag="FFTW_ESTIMATE"):
2525
"""
2626
Compute the sliding dot product between `Q` and `T` using FFTW via pyfftw.
2727
@@ -98,7 +98,7 @@ def __call__(self, Q, T, n_threads=1, planning_flag="FFTW_MEASURE"):
9898
# RFFT(Q)
9999
# Scale by 1/next_fast_n to account for
100100
# FFTW's unnormalized inverse FFT via execute()
101-
real_arr[:m] = Q[::-1] / next_fast_n
101+
np.multiply(Q[::-1], 1.0 / next_fast_n, out=real_arr[:m])
102102
real_arr[m:] = 0.0
103103
rfft_obj.execute() # output is in complex_arr
104104

@@ -114,10 +114,10 @@ def __call__(self, Q, T, n_threads=1, planning_flag="FFTW_MEASURE"):
114114
_sliding_dot_product = SLIDING_DOT_PRODUCT()
115115

116116

117-
def setup(Q, T, n_threads=1, planning_flag="FFTW_MEASURE"):
117+
def setup(Q, T, n_threads=1, planning_flag="FFTW_ESTIMATE"):
118118
_sliding_dot_product(Q, T, n_threads=n_threads, planning_flag=planning_flag)
119119
return
120120

121121

122-
def sliding_dot_product(Q, T, n_threads=1, planning_flag="FFTW_MEASURE"):
122+
def sliding_dot_product(Q, T, n_threads=1, planning_flag="FFTW_ESTIMATE"):
123123
return _sliding_dot_product(Q, T, n_threads=n_threads, planning_flag=planning_flag)

0 commit comments

Comments
 (0)