Elastic Functional KMeans Alignment#

Example clustering functional data that contains phase variability

[1]:
import fdasrsf as fs
import numpy as np

Load in our example data. Example D from

Sangalli, L. M., Secchi, P., Vantini, S., and Vitelli, V. (2010), “k-mean alignment for curve clustering,” Computational Statistics & Data Analysis, 54, 1219–1233. https://doi.org/10.1016/j.csda.2009.12.008.

[2]:
M = 101
N = 90
f = np.zeros((M,N))
t = np.linspace(0, 2*np.pi, M)
cnt = 0
for i in range(30):
    eps = np.random.normal(0, .05, 4)
    f[:, cnt] = (1+eps[0]) * np.sin(eps[2] + (1+eps[3])*t) + (1+eps[1]) * np.sin((eps[2]+(1+eps[3])*t)**2/(2*np.pi))
    cnt += 1

for i in range(30):
    eps = np.random.normal(0, .05, 4)
    f[:, cnt] = (1+eps[0]) * np.sin(-1/3 + eps[2] + (3/4+eps[3])*t) + (1+eps[1]) * np.sin((-1/3+eps[2]+(3/4+eps[3])*t)**2/(2*np.pi))
    cnt += 1

for i in range(30):
    eps = np.random.normal(0, .05, 4)
    f[:, cnt] = (2+eps[0]) * np.sin(eps[2] + (1+eps[3])*t) + (-1+eps[1]) * np.sin((eps[2]+(1+eps[3])*t)**2/(2*np.pi))
    cnt += 1

We will then cluster the data using the kmeans_align function

[3]:
out = fs.kmeans_align(f, t, 3)
updating step: r=1
updating step: r=2
updating step: r=3
updating step: r=4
updating step: r=5
updating step: r=6
updating step: r=7
updating step: r=8
updating step: r=9
_images/example_cluster_5_1.png
_images/example_cluster_5_2.png
_images/example_cluster_5_3.png
_images/example_cluster_5_4.png