phasorpy.cluster#
Cluster phasor coordinates.
The phasorpy.cluster module provides functions to:
fit elliptic clusters to phasor coordinates using Gaussian Mixture Model (GMM):
- phasorpy.cluster.phasor_cluster_gmm(real, imag, /, *, sigma=2.0, clusters=1, **kwargs)[source]#
Return elliptic clusters in phasor coordinates using GMM.
Fit a Gaussian Mixture Model (GMM) to the provided phasor coordinates and extract the parameters of ellipses that represent each cluster according to [1].
- Parameters:
real (array_like) – Real component of phasor coordinates.
imag (array_like) – Imaginary component of phasor coordinates.
sigma (float, default = 2.0) – Scaling factor for radii of major and minor axes. Defaults to 2, which corresponds to the scaling of eigenvalues for a 95% confidence ellipse.
clusters (int, optional) – Number of Gaussian distributions to fit to phasor coordinates. Defaults to 1.
**kwargs –
Additional keyword arguments passed to
sklearn.mixture.GaussianMixture
.Common options include:
covariance_type : {‘full’, ‘tied’, ‘diag’, ‘spherical’}
max_iter : int, maximum number of EM iterations
random_state : int, for reproducible results
- Returns:
center_real (tuple of float) – Real component of ellipse centers.
center_imag (tuple of float) – Imaginary component of ellipse centers.
radius_major (tuple of float) – Major radii of ellipses.
radius_minor (tuple of float) – Minor radii of ellipses.
angle (tuple of float) – Rotation angles of major axes in radians, within range [0, pi].
- Raises:
ValueError – If the array shapes of real and imag do not match. If clusters is not a positive integer.
References
Examples
Recover the clusters from a synthetic distribution of phasor coordinates with two clusters:
>>> real1, imag1 = numpy.random.multivariate_normal( ... [0.2, 0.3], [[3e-3, 1e-3], [1e-3, 2e-3]], 100 ... ).T >>> real2, imag2 = numpy.random.multivariate_normal( ... [0.4, 0.5], [[2e-3, -1e-3], [-1e-3, 3e-3]], 100 ... ).T >>> real = numpy.concatenate([real1, real2]) >>> imag = numpy.concatenate([imag1, imag2]) >>> center_real, center_imag, radius_major, radius_minor, angle = ( ... phasor_cluster_gmm(real, imag, clusters=2) ... ) >>> centers_real (0.2, 0.4)