timeseries.Signal.self_similarity¶
-
Signal.
self_similarity
(window, step=1, start=None, stop=None, dist=<function euclidean>, normalizer=None)[source]¶ Compare sliding windows of this Signal using a distance function.
Parameters: - window (length of segment)
- step (steps to move between windows)
- start (index to start at)
- stop (index to stop at)
- dist (distance function to use. Default:`scipy.spatial.distance.euclidean`
- normalizer (function to use to renormalize each window. default:None)
Returns: - an iterator of the window comparisons.
- (0,0), (0,1), (0,2), … (0, n-1), (1,1), (1,2), … (n-2, n-1)
- The return elements are pairs ((index_lo, index_hi), norm), which
- can be used to populate a dictionary or array.
Examples
>>> S = Signal([0.0, 0.0, 3.0, 4.0, 6.0, 8.0]) >>> Sss = list(S.self_similarity(window=2, step=2)) >>> for (ij, d) in Sss: ... print("{} -> {}".format(ij,d)) (0, 0) -> 0.0 (0, 2) -> 5.0 (0, 4) -> 10.0 (2, 2) -> 0.0 (2, 4) -> 5.0 (4, 4) -> 0.0 >>> D = np.array([d for ij,d in Sss]) >>> print(D) [ 0. 5. 10. 0. 5. 0.] >>> print(ssd.squareform(D)) # scipy.spatial.distance [[ 0. 0. 5. 10.] [ 0. 0. 0. 5.] [ 5. 0. 0. 0.] [ 10. 5. 0. 0.]]