Last active
March 19, 2021 18:32
-
-
Save vncsna/8f99a18253831b6339068a32652607a4 to your computer and use it in GitHub Desktop.
visibility part of sort and conquer algorithm proposed by Ghosh et al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wvisibility(x, left, right, i, graph): | |
'''Weighted visibility module of sort and conquer algorithm proposed by Ghosh et al. | |
Parameters: | |
x: numpy.array | |
A 1d time series. | |
left: int | |
Leftmost node connected to current node. | |
right: int | |
Rightmost node connected to current node. | |
i: int | |
Current node. | |
graph: scipy.sparse.lil.lil_matrix | |
A graph in row-based list of lists format. | |
''' | |
max_slope = float('-inf') | |
min_slope = float('+inf') | |
for j in np.arange(i + 1, right): | |
slope = (x[j] - x[i]) / (j - i) | |
if slope > max_slope: | |
max_slope = slope | |
graph[i, j] = np.arctan(slope) | |
graph[j, i] = np.arctan(slope) | |
for j in np.arange(i - 1, left, -1): | |
slope = (x[i] - x[j]) / (i - j) | |
if slope < min_slope: | |
min_slope = slope | |
graph[i, j] = np.arctan(slope) | |
graph[j, i] = np.arctan(slope) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment