tslearn.barycenters.dtw_barycenter_averaging¶
- tslearn.barycenters.dtw_barycenter_averaging(X, barycenter_size=None, init_barycenter=None, max_iter=30, tol=1e-05, weights=None, metric_params=None, verbose=False, n_init=1)[source]¶
DTW Barycenter Averaging (DBA) method estimated through Expectation-Maximization algorithm.
DBA was originally presented in [1]. This implementation is based on a idea from [2] (Majorize-Minimize Mean Algorithm).
- Parameters:
- Xarray-like, shape=(n_ts, sz, d)
Time series dataset.
- barycenter_sizeint or None (default: None)
Size of the barycenter to generate. If None, the size of the barycenter is that of the data provided at fit time or that of the initial barycenter if specified.
- init_barycenterarray or None (default: None)
Initial barycenter to start from for the optimization process.
- max_iterint (default: 30)
Number of iterations of the Expectation-Maximization optimization procedure.
- tolfloat (default: 1e-5)
Tolerance to use for early stopping: if the decrease in cost is lower than this value, the Expectation-Maximization procedure stops.
- weights: None or array
Weights of each X[i]. Must be the same size as len(X). If None, uniform weights are used.
- metric_params: dict or None (default: None)
DTW constraint parameters to be used. See tslearn.metrics.dtw_path for a list of accepted parameters If None, no constraint is used for DTW computations.
- verboseboolean (default: False)
Whether to print information about the cost at each iteration or not.
- n_initint (default: 1)
Number of different initializations to be tried (useful only is init_barycenter is set to None, otherwise, all trials will reach the same performance)
- Returns:
- numpy.array of shape (barycenter_size, d) or (sz, d) if barycenter_size is None
DBA barycenter of the provided time series dataset.
References
[1]F. Petitjean, A. Ketterlin & P. Gancarski. A global averaging method for dynamic time warping, with applications to clustering. Pattern Recognition, Elsevier, 2011, Vol. 44, Num. 3, pp. 678-693
[2]D. Schultz and B. Jain. Nonsmooth Analysis and Subgradient Methods for Averaging in Dynamic Time Warping Spaces. Pattern Recognition, 74, 340-358.
Examples
>>> time_series = [[1, 2, 3, 4], [1, 2, 4, 5]] >>> dtw_barycenter_averaging(time_series, max_iter=5) array([[1. ], [2. ], [3.5], [4.5]]) >>> time_series = [[1, 2, 3, 4], [1, 2, 3, 4, 5]] >>> dtw_barycenter_averaging(time_series, max_iter=5) array([[1. ], [2. ], [3. ], [4. ], [4.5]]) >>> dtw_barycenter_averaging(time_series, max_iter=5, ... metric_params={"itakura_max_slope": 2}) array([[1. ], [2. ], [3. ], [3.5], [4.5]]) >>> dtw_barycenter_averaging(time_series, max_iter=5, barycenter_size=3) array([[1.5 ], [3. ], [4.33333333]]) >>> dtw_barycenter_averaging([[0, 0, 0], [10, 10, 10]], max_iter=1, ... weights=numpy.array([0.75, 0.25])) array([[2.5], [2.5], [2.5]])