Skip to content

Instantly share code, notes, and snippets.

@vncsna
Last active March 19, 2021 18:32
Show Gist options
  • Save vncsna/88977314ba9ce5daafd9226dd37b3a7f to your computer and use it in GitHub Desktop.
Save vncsna/88977314ba9ce5daafd9226dd37b3a7f to your computer and use it in GitHub Desktop.
main part of sort and conquer algorithm proposed by Ghosh et al
def sort_and_conquer(x):
'''Sort and conquer algorithm proposed by Ghosh et al.
Parameters:
x: numpy.array
A 1d time series.
'''
n = x.size
sortd = np.argsort(x)[::-1]
graph = sparse.lil_matrix((n, n))
for i in np.arange(n):
current = sortd[i]
connected = graph.rows[current]
left = -1
right = n
for j in connected:
if j < current:
left = max(left, j)
else:
right = min(right, j)
wvisibility(x, left, right, current, graph)
return sparse.csr_matrix(graph)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment