Skip to content

Instantly share code, notes, and snippets.

@vncsna
Last active March 19, 2021 18:32
Show Gist options
  • Save vncsna/8f99a18253831b6339068a32652607a4 to your computer and use it in GitHub Desktop.
Save vncsna/8f99a18253831b6339068a32652607a4 to your computer and use it in GitHub Desktop.
visibility part of sort and conquer algorithm proposed by Ghosh et al
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