Skip to content

Commit

Permalink
pull latest changes and resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
NimaSarajpoor committed Nov 7, 2022
2 parents 8d0258a + 65d3e85 commit 428ef8c
Show file tree
Hide file tree
Showing 4 changed files with 1,215 additions and 43 deletions.
35 changes: 31 additions & 4 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@ jobs:
run: sed 's/>/=/g' requirements.txt | sed 's/$/\.*/g' > requirements.min.txt
shell: bash
- name: Install Minimum Requirements
run: pip install --upgrade -r requirements.min.txt
run: python -m pip install --upgrade -r requirements.min.txt
shell: bash
- name: Install STUMPY And Other Dependencies
run: pip install --editable .[ci]
run: python -m pip install --editable .[ci]
shell: bash
- name: Run Black
run: black --check --diff ./
shell: bash
- name: Run Flake8
run: flake8 ./
shell: bash
- name: Link OpenMP
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
brew link --force libomp
fi
shell: bash
- name: Show Full Numba Environment
run: python -m numba -s
shell: bash
- name: Run Unit Tests
run: ./test.sh unit
shell: bash
Expand All @@ -54,14 +63,23 @@ jobs:
run: python -c "import sys; print(sys.version)"
shell: bash
- name: Install STUMPY And Other Dependencies
run: pip install --editable .[ci]
run: python -m pip install --editable .[ci]
shell: bash
- name: Run Black
run: black --check --diff ./
shell: bash
- name: Run Flake8
run: flake8 ./
shell: bash
- name: Link OpenMP
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
brew link --force libomp
fi
shell: bash
- name: Show Full Numba Environment
run: python -m numba -s
shell: bash
- name: Run Unit Tests
run: ./test.sh unit
shell: bash
Expand All @@ -81,14 +99,23 @@ jobs:
run: python -c "import sys; print(sys.version)"
shell: bash
- name: Install STUMPY And Other Dependencies
run: pip install --editable .[ci]
run: python -m pip install --editable .[ci]
shell: bash
- name: Run Black
run: black --check --diff ./
shell: bash
- name: Run Flake8
run: flake8 ./
shell: bash
- name: Link OpenMP
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
brew link --force libomp
fi
shell: bash
- name: Show Full Numba Environment
run: python -m numba -s
shell: bash
- name: Run Coverage Tests
run: ./test.sh coverage
shell: bash
Expand Down
1,124 changes: 1,124 additions & 0 deletions docs/Tutorial_Top-K_Multidimensional_Motif_and_Matches_Discovery.ipynb

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions stumpy/aamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def _compute_diagonal(
"""
n_A = T_A.shape[0]
n_B = T_B.shape[0]
uint64_m = np.uint64(m)
uint64_1 = np.uint64(1)

for diag_idx in range(diags_start_idx, diags_stop_idx):
k = diags[diag_idx]
Expand All @@ -98,41 +100,54 @@ def _compute_diagonal(
iter_range = range(-k, min(n_A - m + 1, n_B - m + 1 - k))

for i in iter_range:
if i == 0 or (k < 0 and i == -k):
uint64_i = np.uint64(i)
uint64_j = np.uint64(i + k)

if uint64_i == 0 or uint64_j == 0:
p_norm = (
np.linalg.norm(T_B[i + k : i + k + m] - T_A[i : i + m], ord=p) ** p
np.linalg.norm(
T_B[uint64_j : uint64_j + uint64_m]
- T_A[uint64_i : uint64_i + uint64_m],
ord=p,
)
** p
)
else:
p_norm = np.abs(
p_norm
- np.absolute(T_B[i + k - 1] - T_A[i - 1]) ** p
+ np.absolute(T_B[i + k + m - 1] - T_A[i + m - 1]) ** p
- np.absolute(T_B[uint64_j - uint64_1] - T_A[uint64_i - uint64_1])
** p
+ np.absolute(
T_B[uint64_j + uint64_m - uint64_1]
- T_A[uint64_i + uint64_m - uint64_1]
)
** p
)

if p_norm < config.STUMPY_P_NORM_THRESHOLD:
p_norm = 0.0

if T_A_subseq_isfinite[i] and T_B_subseq_isfinite[i + k]:
if T_A_subseq_isfinite[uint64_i] and T_B_subseq_isfinite[uint64_j]:
# Neither subsequence contains NaNs
if p_norm < P[thread_idx, i, 0]:
P[thread_idx, i, 0] = p_norm
I[thread_idx, i, 0] = i + k
if p_norm < P[thread_idx, uint64_i, 0]:
P[thread_idx, uint64_i, 0] = p_norm
I[thread_idx, uint64_i, 0] = uint64_j

if ignore_trivial:
if p_norm < P[thread_idx, i + k, 0]:
P[thread_idx, i + k, 0] = p_norm
I[thread_idx, i + k, 0] = i
if p_norm < P[thread_idx, uint64_j, 0]:
P[thread_idx, uint64_j, 0] = p_norm
I[thread_idx, uint64_j, 0] = uint64_i

if i < i + k:
if uint64_i < uint64_j:
# left matrix profile and left matrix profile index
if p_norm < P[thread_idx, i + k, 1]:
P[thread_idx, i + k, 1] = p_norm
I[thread_idx, i + k, 1] = i
if p_norm < P[thread_idx, uint64_j, 1]:
P[thread_idx, uint64_j, 1] = p_norm
I[thread_idx, uint64_j, 1] = uint64_i

# right matrix profile and right matrix profile index
if p_norm < P[thread_idx, i, 2]:
P[thread_idx, i, 2] = p_norm
I[thread_idx, i, 2] = i + k
if p_norm < P[thread_idx, uint64_i, 2]:
P[thread_idx, uint64_i, 2] = p_norm
I[thread_idx, uint64_i, 2] = uint64_j

return

Expand Down
48 changes: 27 additions & 21 deletions stumpy/stump.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def _compute_diagonal(
n_B = T_B.shape[0]
m_inverse = 1.0 / m
constant = (m - 1) * m_inverse * m_inverse # (m - 1)/(m * m)
uint64_m = np.uint64(m)

for diag_idx in range(diags_start_idx, diags_stop_idx):
g = diags[diag_idx]
Expand All @@ -184,10 +185,14 @@ def _compute_diagonal(
iter_range = range(-g, min(n_A - m + 1, n_B - m + 1 - g))

for i in iter_range:
if i == 0 or (g < 0 and i == -g):
uint64_i = np.uint64(i)
uint64_j = np.uint64(i + g)

if uint64_i == 0 or uint64_j == 0:
cov = (
np.dot(
(T_B[i + g : i + g + m] - M_T[i + g]), (T_A[i : i + m] - μ_Q[i])
(T_B[uint64_j : uint64_j + uint64_m] - M_T[uint64_j]),
(T_A[uint64_i : uint64_i + uint64_m] - μ_Q[uint64_i]),
)
* m_inverse
)
Expand All @@ -199,52 +204,53 @@ def _compute_diagonal(
# - (T_B[i + k - 1] - M_T_m_1[i + k]) * (T_A[i - 1] - μ_Q_m_1[i])
# )
cov = cov + constant * (
cov_a[i + g] * cov_b[i] - cov_c[i + g] * cov_d[i]
cov_a[uint64_j] * cov_b[uint64_i]
- cov_c[uint64_j] * cov_d[uint64_i]
)

if T_B_subseq_isfinite[i + g] and T_A_subseq_isfinite[i]:
if T_B_subseq_isfinite[uint64_j] and T_A_subseq_isfinite[uint64_i]:
# Neither subsequence contains NaNs
if T_B_subseq_isconstant[i + g] or T_A_subseq_isconstant[i]:
if T_B_subseq_isconstant[uint64_j] or T_A_subseq_isconstant[uint64_i]:
pearson = 0.5
else:
pearson = cov * Σ_T_inverse[i + g] * σ_Q_inverse[i]
pearson = cov * Σ_T_inverse[uint64_j] * σ_Q_inverse[uint64_i]

if T_B_subseq_isconstant[i + g] and T_A_subseq_isconstant[i]:
if T_B_subseq_isconstant[uint64_j] and T_A_subseq_isconstant[uint64_i]:
pearson = 1.0

# `ρ[thread_idx, i, :]` is sorted ascendingly and MUST be updated
# when the newly-calculated `pearson` value becomes greater than the
# first (i.e. smallest) element in this array. Note that a higher
# pearson value corresponds to a lower distance.
if pearson > ρ[thread_idx, i, 0]:
idx = np.searchsorted(ρ[thread_idx, i], pearson)
idx = np.searchsorted(ρ[thread_idx, uint64_i], pearson)
core._shift_insert_at_index(
ρ[thread_idx, i], idx, pearson, shift="left"
ρ[thread_idx, uint64_i], idx, pearson, shift="left"
)
core._shift_insert_at_index(
I[thread_idx, i], idx, i + g, shift="left"
I[thread_idx, uint64_i], idx, uint64_j, shift="left"
)

if ignore_trivial: # self-joins only
if pearson > ρ[thread_idx, i + g, 0]:
idx = np.searchsorted(ρ[thread_idx, i + g], pearson)
if pearson > ρ[thread_idx, uint64_j, 0]:
idx = np.searchsorted(ρ[thread_idx, uint64_j], pearson)
core._shift_insert_at_index(
ρ[thread_idx, i + g], idx, pearson, shift="left"
ρ[thread_idx, uint64_j], idx, pearson, shift="left"
)
core._shift_insert_at_index(
I[thread_idx, i + g], idx, i, shift="left"
I[thread_idx, uint64_j], idx, uint64_i, shift="left"
)

if i < i + g:
if uint64_i < uint64_j:
# left pearson correlation and left matrix profile index
if pearson > ρL[thread_idx, i + g]:
ρL[thread_idx, i + g] = pearson
IL[thread_idx, i + g] = i
if pearson > ρL[thread_idx, uint64_j]:
ρL[thread_idx, uint64_j] = pearson
IL[thread_idx, uint64_j] = uint64_i

# right pearson correlation and right matrix profile index
if pearson > ρR[thread_idx, i]:
ρR[thread_idx, i] = pearson
IR[thread_idx, i] = i + g
if pearson > ρR[thread_idx, uint64_i]:
ρR[thread_idx, uint64_i] = pearson
IR[thread_idx, uint64_i] = uint64_j

return

Expand Down

0 comments on commit 428ef8c

Please sign in to comment.