pycvi.cluster.compute_center

pycvi.cluster.compute_center(cluster: numpy.ndarray, keepdims: bool = False, avg_kwargs: dict = {}) numpy.ndarray

Compute the center of a cluster.

In the case of static data

For non time-series data, this is simply the average of all datapoints in the given cluster using the usual mean function, and more precisely, calling numpy.mean.

In the case of time series data

For time-series data the cluster center is by default defined as the MBA (MSM DTW barycentric average [DBA]) as defined by Holder et al. [MBA]. In this case, additional parameters can be passed in avg_kwargs, as described in aeon.clustering.averaging.elastic_barycenter_average. By default, uses { "distance": "msm", "init_barycenter": "medoids", "method": "petitjean", "random_state" : 221} .

For more information about the importance of using an elastic average instead of the euclidean mean for time series data, see our example Computing cluster centers

See pycvi.config.default_ts_average_kwargs() for more information about default averaging kwargs used in PyCVI.

[DBA]

F. Petitjean, A. Ketterlin, and P. Gan carski, “A global averaging method for dynamic time warping, with applications to clustering,” Pattern Recognition, vol. 44, pp. 678–693, Mar. 2011.

[MBA]

Christopher Holder, David Guijo-Rubio, and Anthony Bagnall. Barycentre averaging for the move-split-merge time series distance measure. 15th International Joint Conference on Knowledge Discovery, Knowledge Engineering and Knowledge Management (2023)

param cluster:

type cluster:

np.ndarray, shape (N, d*w_t) or (N, w_t, d) if

param ts_dist=True.:

Data values in this cluster.

param keepdims:

Whether to keep the dimension N of the input cluster, by default False.

type keepdims:

bool, optional

param avg_kwargs:

Keyword arguments for the average function. See pycvi.cluster.compute_center() and func:pycvi.cluster.compute_centers for more information.

type avg_kwargs:

dict, optional

returns:
  • np.ndarray, shape (d*w_t), (w_t, d), (1, d*w_t) or ``(1,

  • w_t, d)`` – The cluster center.

    • If keepdims=True then the shape is (1, d*w_t) or (1, w_t, d) if ts_dist=True.

    • If keepdims=False then the shape is (d*w_t) or (w_t, d) if ts_dist=True.

raises ShapeError:

Raised if cluster doesn’t have the shape (N, d*w_t) or (N, w_t, d).