Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def to_subs(ts, sub_len, increment):
- """
- Convert a time-series to a 2D array (num_of_subsequences, sub_len)
- ts: raw time-series
- sub_len: length of subsequences
- increment: overlap of subsequence (increment in loop)
- """
- subs=[]
- for i in range(0,len(ts)-sub_len,increment):
- subs.append(ts[i:i+sub_len])
- return subs
- def unwrap_predictions(preds, ts, sub_len, increment):
- """
- Unwrap predictions for every point.
- Returns unnormalized predictions and mask to normalize (unnorm_preds / mask)
- preds: predictions x sequence, len: num_of_subsequences
- ts: raw time-series
- sub_len: length of subsequences
- increment: overlap of subsequence (increment in loop)
- """
- unwrapped_preds = np.zeros(len(ts))
- mask = np.ones(len(ts))
- for k in range(len(preds)):
- r = np.min([k+1,int(sub_len/increment)])
- for j in range(r):
- unwrapped_preds[increment*(k-j) + j*increment: increment*(k-j) + ((j+1)*increment)] += preds[k]
- mask[increment*(k-j) + j*increment: increment*(k-j) + ((j+1)*increment)] += 1
- return unwrapped_preds, mask
Add Comment
Please, Sign In to add comment