Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

A01_calc_dists_dtw.py 756 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  1. import sys
  2. sys.path.append('..')
  3. import config
  4. import numpy as np
  5. from matplotlib import pyplot as plt
  6. plt.style.use('dark_background')
  7. import data
  8. from util.style import *
  9. from tqdm import tqdm
  10. from scipy.spatial.distance import euclidean
  11. from fastdtw import fastdtw
  12. outcome_def = 'y_consec_thresh'
  13. df = data.get_data()
  14. df = df[df['valid'] == 1] # exclude test cells, short/long tracks, hotspots
  15. n = df.shape[0]
  16. dists = np.zeros((n, n))
  17. for i in tqdm(range(n)):
  18. for j in range(i + 1, n):
  19. x0 = np.array(df['X'].iloc[i])
  20. x1 = np.array(df['X'].iloc[j])
  21. distance, path = fastdtw(x0, x1, dist=euclidean)
  22. dists[i, j] = distance
  23. with open(oj(config.DIR_INTERIM, 'dists_dtw.npy'), 'wb') as f:
  24. np.save(f, dists)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...