def _compute_J(x, window_starts, L):
"""Compute the cost, which is proportional to the
difference between pairs of windows"""
# Get all windows and zscore them
N_windows = len(window_starts)
windows = np.zeros((N_windows, L))
for w in range(N_windows):
temp = x[window_starts[w]:window_starts[w] + L]
windows[w] = (temp - np.mean(temp)) / np.std(temp)
# Calculate distances for all pairs of windows
dist = pdist(np.vstack(windows),
lambda u, v: np.sum((u - v) ** 2))
J = np.sum(dist) / float(L * (N_windows - 1))
return J
评论列表
文章目录