Guest User

Untitled

a guest
Mar 23rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. def to_subs(ts, sub_len, increment):
  2. """
  3. Convert a time-series to a 2D array (num_of_subsequences, sub_len)
  4. ts: raw time-series
  5. sub_len: length of subsequences
  6. increment: overlap of subsequence (increment in loop)
  7. """
  8. subs=[]
  9. for i in range(0,len(ts)-sub_len,increment):
  10. subs.append(ts[i:i+sub_len])
  11. return subs
  12.  
  13. def unwrap_predictions(preds, ts, sub_len, increment):
  14. """
  15. Unwrap predictions for every point.
  16. Returns unnormalized predictions and mask to normalize (unnorm_preds / mask)
  17. preds: predictions x sequence, len: num_of_subsequences
  18. ts: raw time-series
  19. sub_len: length of subsequences
  20. increment: overlap of subsequence (increment in loop)
  21. """
  22. unwrapped_preds = np.zeros(len(ts))
  23. mask = np.ones(len(ts))
  24. for k in range(len(preds)):
  25. r = np.min([k+1,int(sub_len/increment)])
  26. for j in range(r):
  27. unwrapped_preds[increment*(k-j) + j*increment: increment*(k-j) + ((j+1)*increment)] += preds[k]
  28. mask[increment*(k-j) + j*increment: increment*(k-j) + ((j+1)*increment)] += 1
  29.  
  30. return unwrapped_preds, mask
Add Comment
Please, Sign In to add comment