Artificial Intelligence Applications in Engineering (MUH-920), week 9 of 14

Patterns without Labels: Clustering, Signals and Anomaly Detection

Prof. Dr. Utku Kose, Süleyman Demirel University

Learning without labels

Supervised learning needs a label for every example. In engineering, labels are expensive: A geologist must interpret each metre of a well, a technician must confirm each fault, and many rare events have never been observed. Unsupervised learning works with the inputs alone. Clustering groups similar records, dimensionality reduction summarises many correlated variables with a few, and anomaly detection flags records that differ from the bulk of the data [1, 2]. The results are hypotheses that domain experts must interpret: A cluster is not a rock type, and an anomaly is not a fault, until someone checks.

k-means and the choice of k

k-means represents each cluster by a centre and alternates two steps: assign every point to its nearest centre, then move every centre to the mean of its points. Each step lowers the sum of squared distances, so the procedure converges, although only to a local optimum [3, 4]. The k-means++ initialisation spreads the initial centres out and improves both speed and quality [5]. Because k-means uses Euclidean distance, inputs with large numerical ranges dominate unless they are scaled; gamma-ray counts in API units would otherwise swamp a photoelectric factor.

The number of clusters is a modelling choice. The within-cluster sum of squares always falls as k grows, so the elbow of its curve is only a rough guide. The silhouette of a point compares its mean distance to its own cluster with that to the nearest other cluster, and the average silhouette over all points is highest for well-separated, compact clusters [6]. Neither criterion knows the physics; well logs may form five clear clusters although geologists distinguish nine facies.

Animation: The two steps of k-means

Press Step to alternate between assigning points to the nearest centre and moving each centre to the mean of its points. Try several restarts: Different initial centres can end in different solutions.

Check your understanding. Why must the inputs usually be standardised before k-means?

Formulas: The k-means objective, k-means++ and the silhouette

k-means divides nn points xix_i into kk clusters C1,…,CkC_1, \ldots, C_k with centres μ1,…,μk\mu_1, \ldots, \mu_k and minimises the within-cluster sum of squares [3, 4]:

W=∑j=1k∑xi∈Cj∥xi−μj∥2W = \sum_{j=1}^{k} \sum_{x_i \in C_j} \lVert x_i - \mu_j \rVert^2

The double bars denote the Euclidean length of a vector, so ∥xi−μj∥2\lVert x_i - \mu_j \rVert^2 is the squared distance. The algorithm alternates two steps, each of which can only lower WW: The assignment step gives every point to its nearest centre, and the update step moves every centre to the mean of its points,

c(i)=arg⁡min⁡j∥xi−μj∥2,    μj=1∣Cj∣∑xi∈Cjxic(i) = \arg\min_{j} \lVert x_i - \mu_j \rVert^2, \;\; \mu_j = \frac{1}{|C_j|} \sum_{x_i \in C_j} x_i

k-means++ chooses the first centre at random and every further centre with a probability proportional to the squared distance D(x)2D(x)^2 of a point to the nearest centre chosen so far [5]:

P(x)=D(x)2∑x′D(x′)2P(x) = \frac{D(x)^2}{\sum_{x'} D(x')^2}

The silhouette of a point compares its mean distance a(i)a(i) to the other points of its cluster with its mean distance b(i)b(i) to the points of the nearest other cluster [6]:

s(i)=b(i)−a(i)max⁡(a(i),b(i))s(i) = \frac{b(i) - a(i)}{\max(a(i), b(i))}

Values near 1 mark points deep inside their cluster, values near 0 points between clusters, and negative values points that sit closer to another cluster.

Worked example: One iteration of k-means

Six points, A (1,1)(1, 1), B (1.5,2)(1.5, 2), C (3,3.5)(3, 3.5), D (5,7)(5, 7), E (3.5,5)(3.5, 5) and F (4.5,5)(4.5, 5), are clustered with k=2k = 2, starting from μ1=(1,1)\mu_1 = (1, 1) and μ2=(5,7)\mu_2 = (5, 7).

Step 1. Assignment. The squared distances to the two centres, for example ∥C−μ1∥2=(3−1)2+(3.5−1)2=4+6.25=10.25\lVert C - \mu_1 \rVert^2 = (3 - 1)^2 + (3.5 - 1)^2 = 4 + 6.25 = 10.25 and ∥C−μ2∥2=(3−5)2+(3.5−7)2=4+12.25=16.25\lVert C - \mu_2 \rVert^2 = (3 - 5)^2 + (3.5 - 7)^2 = 4 + 12.25 = 16.25:

Point Coordinates To μ1\mu_1 To μ2\mu_2 Cluster
A (1,1)(1, 1) 0 52 1
B (1.5,2)(1.5, 2) 1.25 37.25 1
C (3,3.5)(3, 3.5) 10.25 16.25 1
D (5,7)(5, 7) 52 0 2
E (3.5,5)(3.5, 5) 22.25 6.25 2
F (4.5,5)(4.5, 5) 28.25 4.25 2

The sum of the smaller squared distances is W=0+1.25+10.25+0+6.25+4.25=22W = 0 + 1.25 + 10.25 + 0 + 6.25 + 4.25 = 22.

Step 2. Update.

μ1=(1+1.5+33,1+2+3.53)=(5.53,6.53)=(1.8333,2.1667)\mu_1 = \left(\frac{1 + 1.5 + 3}{3}, \frac{1 + 2 + 3.5}{3}\right) = \left(\frac{5.5}{3}, \frac{6.5}{3}\right) = (1.8333, 2.1667)
μ2=(5+3.5+4.53,7+5+53)=(133,173)=(4.3333,5.6667)\mu_2 = \left(\frac{5 + 3.5 + 4.5}{3}, \frac{7 + 5 + 5}{3}\right) = \left(\frac{13}{3}, \frac{17}{3}\right) = (4.3333, 5.6667)

Step 3. The new objective. For A, ∥A−μ1∥2=(1−1.833333)2+(1−2.166667)2=0.694444+1.361111=2.055556\lVert A - \mu_1 \rVert^2 = (1 - 1.833333)^2 + (1 - 2.166667)^2 = 0.694444 + 1.361111 = 2.055556, and in the same way the squared distances to the new centres are 2.055556, 0.138889, 3.138889 in cluster 1 and 2.222222, 1.138889, 0.472222 in cluster 2, so

W=2.055556+0.138889+3.138889+2.222222+1.138889+0.472222=9.166667W = 2.055556 + 0.138889 + 3.138889 + 2.222222 + 1.138889 + 0.472222 = 9.166667

much less than 22. A second assignment step leaves every point in its cluster, so the algorithm has converged.

Worked example: Seeding with k-means++ and two silhouettes

Step 1. The second centre. With A as the first centre, the squared distances of the other points are B 1.25, C 10.25, D 52, E 22.25, F 28.25, which add up to 114. The probabilities are B 0.011, C 0.0899, D 0.4561, E 0.1952, F 0.2478, with the cumulative values 0.011, 0.1009, 0.557, 0.7522, 1. A random number of 0.6 falls in the interval of E, which becomes the second centre; the far points D, E and F together had a probability of 0.8991.

Step 2. The silhouette of A. a=(1.118034+3.201562)/2=2.159798a = (1.118034 + 3.201562)/2 = 2.159798 from the distances to B and C, and b=(7.211103+4.716991+5.315073)/3=5.747722b = (7.211103 + 4.716991 + 5.315073)/3 = 5.747722 from the distances to D, E and F, so

s(A)=5.747722−2.1597985.747722=0.624234s(A) = \frac{5.747722 - 2.159798}{5.747722} = 0.624234

Step 3. The silhouette of C. a=(3.201562+2.12132)/2=2.661441a = (3.201562 + 2.12132)/2 = 2.661441 and b=(4.031129+1.581139+2.12132)/3=2.577863b = (4.031129 + 1.581139 + 2.12132)/3 = 2.577863, so

s(C)=2.577863−2.6614412.661441=−0.031403s(C) = \frac{2.577863 - 2.661441}{2.661441} = −0.031403

C belongs to cluster 1 by its distance to the centres, yet on average it lies closer to the points of cluster 2. Its negative silhouette marks it as a point between clusters, which an expert should inspect. Part A of the interactive lab computes all these quantities for any points.

Principal component analysis

Principal component analysis finds orthogonal directions along which the data vary most [7, 8]. The first component is the direction of largest variance, the second the largest remaining variance orthogonal to the first, and so on. The explained variance ratio of each component shows how much information a projection keeps, and the loadings show how each original variable contributes. In well logging, the first components often combine porosity and density logs, which respond to the same rock properties. PCA serves visualisation, compression, noise reduction and the detection of anomalies as points that the leading components reconstruct poorly.

Formulas: Principal components from the covariance matrix

The nn observations of pp variables are first centred by subtracting each variable's mean. The covariance matrix SS collects the variances on its diagonal and the covariances off it [8]:

Sjl=1n−1∑i=1n(xij−x‾j)(xil−x‾l)S_{jl} = \frac{1}{n - 1} \sum_{i=1}^{n} (x_{ij} - \overline{x}_j)(x_{il} - \overline{x}_l)

The principal components are the eigenvectors vv of SS, the directions that SS only stretches, Sv=λvS v = \lambda v, and the eigenvalue λ\lambda is the variance of the data along vv [7]. For two variables the eigenvalues solve a quadratic equation in the trace tr=S11+S22\text{tr} = S_{11} + S_{22} and the determinant det⁡=S11S22−S122\det = S_{11} S_{22} - S_{12}^2:

λ1,2=tr±tr2−4det⁡2\lambda_{1,2} = \frac{\text{tr} \pm \sqrt{\text{tr}^2 - 4 \det}}{2}

and the first row of (S−λ1I)v=0(S - \lambda_1 I) v = 0 gives the direction v∝(1,(λ1−S11)/S12)v \propto (1, (\lambda_1 - S_{11})/S_{12}), scaled to length one. The explained variance ratio of component jj is λj/∑lλl\lambda_j / \sum_l \lambda_l. A centred observation xx has the score z=x⋅v1z = x \cdot v_1 on the first component, its reconstruction from that component alone is x^=z v1\hat{x} = z\, v_1, and the reconstruction error ∥x−x^∥2\lVert x - \hat{x} \rVert^2 serves as an anomaly score.

Worked example: Two porosity logs

Five depth samples give a density porosity of 8, 9, 10, 11, 12 percent and a neutron porosity of 10.5, 11, 12, 12.5, 14 percent.

Step 1. Centring. The means are 10 and 12, so the centred values are −2, −1, 0, 1, 2 and −1.5, −1, 0, 0.5, 2.

Step 2. The covariance matrix.

S11=4+1+0+1+44=2.5,    S22=2.25+1+0+0.25+44=1.875S_{11} = \frac{4 + 1 + 0 + 1 + 4}{4} = 2.5, \;\; S_{22} = \frac{2.25 + 1 + 0 + 0.25 + 4}{4} = 1.875
S12=(−2)(−1.5)+(−1)(−1)+0×0+1×0.5+2×24=3+1+0+0.5+44=2.125S_{12} = \frac{(-2)(-1.5) + (-1)(-1) + 0 \times 0 + 1 \times 0.5 + 2 \times 2}{4} = \frac{3 + 1 + 0 + 0.5 + 4}{4} = 2.125

Step 3. Eigenvalues. tr=2.5+1.875=4.375\text{tr} = 2.5 + 1.875 = 4.375 and det⁡=2.5×1.875−2.1252=4.6875−4.515625=0.171875\det = 2.5 \times 1.875 - 2.125^2 = 4.6875 - 4.515625 = 0.171875:

λ1,2=4.375±4.3752−4×0.1718752=4.375±18.4531252=4.375±4.295712\lambda_{1,2} = \frac{4.375 \pm \sqrt{4.375^2 - 4 \times 0.171875}}{2} = \frac{4.375 \pm \sqrt{18.453125}}{2} = \frac{4.375 \pm 4.29571}{2}

so λ1=4.335355\lambda_1 = 4.335355 and λ2=0.039645\lambda_2 = 0.039645.

Step 4. The first direction. (λ1−S11)/S12=(4.335355−2.5)/2.125=0.863696(\lambda_1 - S_{11})/S_{12} = (4.335355 - 2.5)/2.125 = 0.863696, and the length of (1,0.863696)(1, 0.863696) is 1+0.8636962=1.321352\sqrt{1 + 0.863696^2} = 1.321352, so v1=(0.756801,0.653646)v_1 = (0.756801, 0.653646).

Step 5. Explained variance. 4.335355/4.375=0.9909384.335355/4.375 = 0.990938: The first component keeps 99.1 percent of the variance, because both logs respond to the same porosity.

Step 6. Score and reconstruction of the last sample. For the centred sample (2,2)(2, 2):

z=2×0.756801+2×0.653646=2.820894z = 2 \times 0.756801 + 2 \times 0.653646 = 2.820894
x^=2.820894×(0.756801,0.653646)=(2.134855,1.843866)\hat{x} = 2.820894 \times (0.756801, 0.653646) = (2.134855, 1.843866)
∥x−x^∥2=(2−2.134855)2+(2−1.843866)2=0.042564\lVert x - \hat{x} \rVert^2 = (2 - 2.134855)^2 + (2 - 1.843866)^2 = 0.042564

A sample whose logs disagree, for example because of a washed-out borehole, would lie far from the first direction and show a much larger error. Part B of the interactive lab computes these steps for any data.

Density-based clustering

Clusters in engineering data are not always round. Earthquakes line up along faults, defects form streaks on a web of fabric, and traffic accidents gather along roads. DBSCAN defines clusters as regions of high density: A point with at least a minimum number of neighbours within a radius eps is a core point, clusters grow by connecting core points that are neighbours, and points that belong to no cluster are labelled noise [9]. DBSCAN finds clusters of arbitrary shape and does not need the number of clusters, but eps and the minimum number of points must fit the density of the data. For epicentres, distances should be measured on the sphere, for example with the haversine formula, rather than in degrees.

Check your understanding. Aftershocks form an elongated band along a fault, surrounded by scattered background events. Which method suits this pattern best?

Formulas: DBSCAN and distances on the sphere

DBSCAN uses two parameters, a radius ε\varepsilon and a minimum number of points mm [9]. The ε\varepsilon-neighbourhood of a point pp, which includes pp itself, is

Nε(p)={q:d(p,q)≤ε}N_{\varepsilon}(p) = \{ q : d(p, q) \le \varepsilon \}

A point is a core point when ∣Nε(p)∣≥m|N_{\varepsilon}(p)| \ge m. A cluster is grown from a core point by adding its neighbours and, recursively, the neighbours of every core point among them. A point that is not a core point but lies in the neighbourhood of one is a border point, and every remaining point is noise. Epicentres are given by latitude φ\varphi and longitude λ\lambda on a sphere of radius R=6371R = 6371 km, and the great-circle distance between two of them follows from the haversine formula, with all angles in radians:

a=sin⁡2(Δφ2)+cos⁡φ1cos⁡φ2sin⁡2(Δλ2),    d=2Rarcsin⁡aa = \sin^2\left(\frac{\Delta\varphi}{2}\right) + \cos\varphi_1 \cos\varphi_2 \sin^2\left(\frac{\Delta\lambda}{2}\right), \;\; d = 2R \arcsin\sqrt{a}

A degree of latitude is always 2πR/360=111.1952\pi R/360 = 111.195 km long, while a degree of longitude shrinks with cos⁡φ\cos\varphi, so distances computed directly in degrees are wrong in the east-west direction.

Worked example: Core, border and noise points

Eight points on a map, in kilometres, are clustered with ε=1.2\varepsilon = 1.2 km and m=3m = 3. The distance between P1 and P4 is 12+12=1.414>1.2\sqrt{1^2 + 1^2} = 1.414 > 1.2, so they are not neighbours, while P4 and P5 are 1 km apart:

Point Coordinates Neighbourhood NεN_{\varepsilon} Size Type
P1 (0,0)(0, 0) P1, P2, P3 3 core
P2 (1,0)(1, 0) P1, P2, P4 3 core
P3 (0,1)(0, 1) P1, P3, P4 3 core
P4 (1,1)(1, 1) P2, P3, P4, P5 4 core
P5 (2,1)(2, 1) P4, P5 2 border
P6 (5,5)(5, 5) P6, P7 2 noise
P7 (5.5,5)(5.5, 5) P6, P7 2 noise
P8 (9,0)(9, 0) P8 1 noise

P1 to P4 are core points and form one cluster. P5 has only two points in its neighbourhood but lies next to the core point P4, so it joins the cluster as a border point. P6 and P7 are close to each other, but neither has three points in its neighbourhood, so both are noise, as is the isolated P8. With m=2m = 2, P6 and P7 would form a second cluster: The parameters must match the density of the data. Part C of the interactive lab places points by clicking and compares k-means with DBSCAN on the same data.

Worked example: The distance between two epicentres

Two epicentres lie at 37.2∘37.2^{\circ} N, 37.0∘37.0^{\circ} E and 38.0∘38.0^{\circ} N, 37.2∘37.2^{\circ} E.

Step 1. Differences in radians. Δφ=0.8×π/180=0.013963\Delta\varphi = 0.8 \times \pi/180 = 0.013963 and Δλ=0.2×π/180=0.003491\Delta\lambda = 0.2 \times \pi/180 = 0.003491.

Step 2. The haversine term.

sin⁡2(0.013963/2)=0.0000487406,    sin⁡2(0.003491/2)=0.0000030468\sin^2(0.013963/2) = 0.0000487406, \;\; \sin^2(0.003491/2) = 0.0000030468
cos⁡37.2∘=0.79653,    cos⁡38∘=0.788011\cos 37.2^{\circ} = 0.79653, \;\; \cos 38^{\circ} = 0.788011
a=0.0000487406+0.79653×0.788011×0.0000030468=0.000050653a = 0.0000487406 + 0.79653 \times 0.788011 \times 0.0000030468 = 0.000050653

Step 3. The distance. 2arcsin⁡0.000050653=0.01423432 \arcsin\sqrt{0.000050653} = 0.0142343, so d=6371×0.0142343=90.69d = 6371 \times 0.0142343 = 90.69 km.

Step 4. The error of degrees. Treating degrees as a flat grid gives 0.82+0.22×111.195=91.69\sqrt{0.8^2 + 0.2^2} \times 111.195 = 91.69 km, close here because the separation is mostly north-south. For two points one degree apart in longitude at 38∘38^{\circ} N, however, the true distance is about 111.195×cos⁡38∘=87.62111.195 \times \cos 38^{\circ} = 87.62 km, while degrees would give 111.195 km, an error of 27 percent that would distort every ε\varepsilon-neighbourhood. Part D of the interactive lab clusters epicentres with haversine distances.

Signals in the frequency domain

Many engineering sensors produce time series sampled at a fixed rate: accelerometers on machines, microphones, current transducers, seismometers. The discrete Fourier transform expresses a sampled signal as a sum of sinusoids, and the fast Fourier transform computes it efficiently [10]. The sampling rate fs limits the highest frequency that can be represented to fs / 2, the Nyquist frequency, and a record of duration T resolves frequencies that differ by 1 / T. Rotating machines produce peaks at the shaft frequency and its harmonics, and faults add their own frequencies.

A rolling-element bearing with a damaged outer race produces an impact every time a rolling element passes the damage. The ball pass frequency of the outer race is BPFO = (n / 2) fr (1 - (d / D) cos phi), with n rolling elements of diameter d, pitch diameter D, contact angle phi and shaft frequency fr. The impacts excite structural resonances at high frequency, so the fault frequency often appears not in the raw spectrum but in the spectrum of the signal's envelope, obtained after demodulation. Envelope analysis is the benchmark technique of bearing diagnostics [11], and the Case Western Reserve University data are the standard test set for it [12]. Simple condition indicators complement spectra: the root mean square (RMS) measures vibration energy, kurtosis measures impulsiveness, and the crest factor compares the peak with the RMS.

Check your understanding. A bearing has 9 balls, d / D = 0.2034, contact angle zero, and the shaft turns at 30 Hz. What is the BPFO?

Formulas: The discrete Fourier transform, bearing frequencies and condition indicators

A signal sampled at the rate fsf_s gives NN values x0,…,xN−1x_0, \ldots, x_{N-1} over the duration T=N/fsT = N/f_s. The discrete Fourier transform writes it as a sum of complex sinusoids with the coefficients [10]

Xk=∑n=0N−1xn e−i2πkn/N,    k=0,1,…,N−1X_k = \sum_{n=0}^{N-1} x_n\, e^{-i 2\pi k n / N}, \;\; k = 0, 1, \ldots, N - 1

where ii is the imaginary unit and e−iθ=cos⁡θ−isin⁡θe^{-i\theta} = \cos\theta - i \sin\theta. Coefficient kk belongs to the frequency fk=kfs/Nf_k = k f_s/N, so neighbouring bins are Δf=fs/N=1/T\Delta f = f_s/N = 1/T apart, and the highest frequency that can be represented is the Nyquist frequency fs/2f_s/2. The mean of the signal is X0/NX_0/N, and a sinusoid that falls exactly on bin kk has the amplitude 2∣Xk∣/N2|X_k|/N. For a bearing with nn rolling elements of diameter dd on the pitch diameter DD, with contact angle ϕ\phi and shaft frequency frf_r, the characteristic frequencies are [11]

BPFO=n2fr(1−dDcos⁡ϕ),    BPFI=n2fr(1+dDcos⁡ϕ)\text{BPFO} = \frac{n}{2} f_r \left(1 - \frac{d}{D}\cos\phi\right), \;\; \text{BPFI} = \frac{n}{2} f_r \left(1 + \frac{d}{D}\cos\phi\right)
FTF=fr2(1−dDcos⁡ϕ),    BSF=D2dfr(1−(dDcos⁡ϕ)2)\text{FTF} = \frac{f_r}{2} \left(1 - \frac{d}{D}\cos\phi\right), \;\; \text{BSF} = \frac{D}{2d} f_r \left(1 - \left(\frac{d}{D}\cos\phi\right)^2\right)

for the outer race, the inner race, the cage and the spin of a rolling element. The impacts at these rates modulate a high-frequency resonance; envelope analysis takes the magnitude of the analytic signal, ∣x(t)+i H{x}(t)∣|x(t) + i\,\text{H}\{x\}(t)|, where H denotes the Hilbert transform, and the fault frequencies appear in the spectrum of this envelope. Three simple indicators summarise a record:

RMS=1N∑nxn2,    crest factor=max⁡n∣xn∣RMS,    kurtosis=1N∑n(xn−x‾)4(1N∑n(xn−x‾)2)2\text{RMS} = \sqrt{\frac{1}{N}\sum_{n} x_n^2}, \;\; \text{crest factor} = \frac{\max_n |x_n|}{\text{RMS}}, \;\; \text{kurtosis} = \frac{\frac{1}{N}\sum_n (x_n - \overline{x})^4}{\left(\frac{1}{N}\sum_n (x_n - \overline{x})^2\right)^2}

A Gaussian signal has a kurtosis of 3; impacts raise it.

Worked example: A four-point Fourier transform

The samples x=(2,1,0,1)x = (2, 1, 0, 1) are taken at fs=1000f_s = 1000 Hz.

Step 1. The rotating factors. For k=1k = 1 and N=4N = 4, e−i2πn/4e^{-i 2\pi n/4} takes the values 11, −i-i, −1-1 and ii for n=0,1,2,3n = 0, 1, 2, 3; for k=2k = 2 the values 1,−1,1,−11, -1, 1, -1; for k=3k = 3 the values 1,i,−1,−i1, i, -1, -i.

Step 2. The coefficients.

X0=2+1+0+1=4,    X1=2×1+1×(−i)+0×(−1)+1×i=2X_0 = 2 + 1 + 0 + 1 = 4, \;\; X_1 = 2 \times 1 + 1 \times (-i) + 0 \times (-1) + 1 \times i = 2
X2=2−1+0−1=0,    X3=2+i+0−i=2X_2 = 2 - 1 + 0 - 1 = 0, \;\; X_3 = 2 + i + 0 - i = 2

Step 3. Interpretation. The bins are Δf=1000/4=250\Delta f = 1000/4 = 250 Hz apart. The mean is X0/4=1X_0/4 = 1, and bin 1, at 250 Hz, holds a sinusoid of amplitude 2×2/4=12 \times 2/4 = 1: Indeed xn=1+cos⁡(2πn/4)x_n = 1 + \cos(2\pi n/4). Bin 3 mirrors bin 1, as for every real signal, and lies above the Nyquist frequency of 500 Hz. Part E of the interactive lab computes the Fourier coefficients of any short signal term by term.

Worked example: Bearing frequencies and indicators

Step 1. Fault frequencies. For n=9n = 9, d/D=0.2034d/D = 0.2034, ϕ=0\phi = 0 and fr=30f_r = 30 Hz, as in the knowledge check:

BPFO=4.5×30×(1−0.2034)=135×0.7966=107.541 Hz,    BPFI=135×1.2034=162.459 Hz\text{BPFO} = 4.5 \times 30 \times (1 - 0.2034) = 135 \times 0.7966 = 107.541 \text{ Hz}, \;\; \text{BPFI} = 135 \times 1.2034 = 162.459 \text{ Hz}
FTF=15×0.7966=11.949 Hz,    BSF=302×0.2034×(1−0.20342)=70.695 Hz\text{FTF} = 15 \times 0.7966 = 11.949 \text{ Hz}, \;\; \text{BSF} = \frac{30}{2 \times 0.2034} \times (1 - 0.2034^2) = 70.695 \text{ Hz}

At the 1797 rpm of the Case Western Reserve data, fr=1797/60=29.95f_r = 1797/60 = 29.95 Hz, and the BPFO is 4.5×29.95×0.7966=107.364.5 \times 29.95 \times 0.7966 = 107.36 Hz [12].

Step 2. Resolution. A record sampled at 12 kHz for one second gives Δf=12000/12000=1\Delta f = 12000/12000 = 1 Hz, fine enough to separate BPFO from its neighbours, and a Nyquist frequency of 6000 Hz.

Step 3. Indicators of a short record. The samples 0.5, −0.4, 0.3, 3, −0.6, 0.4, −0.5, 0.3 contain one impact. Their squares add up to 10.36, so RMS=10.36/8=1.137981\text{RMS} = \sqrt{10.36/8} = 1.137981 and the crest factor is 3/1.137981=2.6362483/1.137981 = 2.636248. The mean is 3/8=0.3753/8 = 0.375; the squared deviations from it add up to 9.235, so the variance is 1.154375, and the fourth powers add up to 49.331641, so 18∑(x−x‾)4=6.166455\frac{1}{8}\sum (x - \overline{x})^4 = 6.166455 and

kurtosis=6.1664551.1543752=4.6275\text{kurtosis} = \frac{6.166455}{1.154375^2} = 4.6275

well above 3, which flags the impulsive content. Part F of the interactive lab computes the frequencies for any bearing and the indicators for any record, and Part G synthesises the vibration of a bearing and shows its waveform, spectrum and envelope spectrum.

Anomaly detection

An anomaly detector learns what normal data look like and scores how unusual a new record is [2]. Statistical rules flag values far from the mean in units of standard deviation. Reconstruction-based methods flag records that a PCA model or an autoencoder reconstructs poorly. Isolation forests grow random trees that split the data at random thresholds; anomalies are isolated after few splits, so the average path length to isolate a point becomes its score [13]. In condition monitoring, detectors are usually trained on data from normal operation, because faults are rare and diverse. The alarm threshold, as in Week 8, depends on the costs of false alarms and missed faults, and a detector must be re-examined when operating conditions change, since a new load or speed can look like an anomaly [14].

Spectrum and envelope spectrum of a synthetic vibration signal from a bearing with an outer-race defect. The fault frequency and its harmonics stand out only in the envelope spectrum .
Figure 9.1. Spectrum and envelope spectrum of a synthetic vibration signal from a bearing with an outer-race defect. The fault frequency and its harmonics stand out only in the envelope spectrum [11].

Check your understanding. An isolation forest was trained on vibration features from a pump at 50 percent load. After the load is raised to 90 percent, alarms rise sharply although the pump is healthy. What is the most likely explanation?

Formulas: Statistical rules and the isolation forest

A simple rule flags a value xx whose standardised distance from the mean of normal data exceeds a limit, often 3: ∣z∣=∣x−μ∣/σ>3|z| = |x - \mu|/\sigma > 3. Reconstruction-based methods flag records with a large error ∥x−x^∥2\lVert x - \hat{x} \rVert^2, as in the PCA example. An isolation forest grows random trees on subsamples of ψ\psi points, splitting on a random feature at a random value, and records the number of edges h(x)h(x) from the root to the leaf that isolates a point. Its anomaly score normalises the mean path length over all trees by the average path length c(ψ)c(\psi) of an unsuccessful search in a binary tree [13]:

s(x)=2−E[h(x)]/c(ψ),    c(ψ)=2H(ψ−1)−2(ψ−1)ψs(x) = 2^{-\text{E}[h(x)]/c(\psi)}, \;\; c(\psi) = 2 H(\psi - 1) - \frac{2(\psi - 1)}{\psi}

with the harmonic number H(i)≈ln⁡i+0.5772156649H(i) \approx \ln i + 0.5772156649, where the constant is Euler's constant. Scores close to 1 mark anomalies, scores well below 0.5 normal points, and a score of 0.5 means that E[h(x)]=c(ψ)\text{E}[h(x)] = c(\psi).

Worked example: Two detectors

Step 1. A three-sigma rule. A bearing temperature has μ=70∘C\mu = 70^{\circ}\text{C} and σ=2.5∘C\sigma = 2.5^{\circ}\text{C} in normal operation. A reading of 78.5∘C78.5^{\circ}\text{C} gives z=(78.5−70)/2.5=8.5/2.5=3.4z = (78.5 - 70)/2.5 = 8.5/2.5 = 3.4, beyond 3, so it is flagged.

Step 2. The normalising constant. With subsamples of ψ=256\psi = 256 points, as recommended by Liu and colleagues:

H(255)=ln⁡255+0.5772156649=5.541264+0.577216=6.118479H(255) = \ln 255 + 0.5772156649 = 5.541264 + 0.577216 = 6.118479
c(256)=2×6.118479−2×255256=12.236958−1.992188=10.24477c(256) = 2 \times 6.118479 - \frac{2 \times 255}{256} = 12.236958 - 1.992188 = 10.24477

Step 3. Two scores. A point isolated after 4 splits on average scores 2−4/10.24477=2−0.390443=0.7628952^{-4/10.24477} = 2^{-0.390443} = 0.762895, an anomaly. A point that needs 14 splits scores 2−14/10.24477=2−1.366551=0.3878172^{-14/10.24477} = 2^{-1.366551} = 0.387817, a normal point. Few splits isolate a point when it lies far from the others, which is the idea of the method. Part H of the interactive lab isolates points with random splits.

Python step 9: Signals, features and clustering with NumPy

The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code. The Colab button below opens the notebook at the step. Run the setup cell just above the step first, since the exercises use its check function.

Open Python step 9 in Colab View the notebook on GitHub

Review cards

Select a card to turn it over.

k-means
Alternate assignment to the nearest centre and centre update; minimises within-cluster squared distances [3].
Silhouette
Compares a point's distance to its own cluster with that to the nearest other cluster; ranges from -1 to 1 [6].
Principal component
Orthogonal direction of maximal remaining variance in the data [8].
DBSCAN
Density-based clustering with core points, reachability and noise; parameters eps and min_samples [9].
BPFO
(n / 2) fr (1 - (d / D) cos phi): the outer-race fault frequency of a rolling bearing.
Isolation forest
Random trees isolate anomalies in few splits; the path length is the anomaly score [13].

Continue the week

The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.

Interactive lab Colab notebook Self-assessment Week overview and tasks

References

[1] Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. https://doi.org/10.1007/978-0-387-84858-7

[2] Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), 15. https://doi.org/10.1145/1541880.1541882

[3] Lloyd, S. (1982). Least squares quantization in PCM. IEEE Transactions on Information Theory, 28(2), 129-137. https://doi.org/10.1109/TIT.1982.1056489

[4] MacQueen, J. (1967). Some methods for classification and analysis of multivariate observations. In Proceedings of the Fifth Berkeley Symposium on Mathematical Statistics and Probability, Vol. 1 (pp. 281-297). University of California Press.

[5] Arthur, D., & Vassilvitskii, S. (2007). k-means++: The advantages of careful seeding. In Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms (pp. 1027-1035). SIAM.

[6] Rousseeuw, P. J. (1987). Silhouettes: A graphical aid to the interpretation and validation of cluster analysis. Journal of Computational and Applied Mathematics, 20, 53-65. https://doi.org/10.1016/0377-0427(87)90125-7

[7] Pearson, K. (1901). On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 2(11), 559-572. https://doi.org/10.1080/14786440109462720

[8] Jolliffe, I. T., & Cadima, J. (2016). Principal component analysis: A review and recent developments. Philosophical Transactions of the Royal Society A, 374(2065), 20150202. https://doi.org/10.1098/rsta.2015.0202

[9] Ester, M., Kriegel, H.-P., Sander, J., & Xu, X. (1996). A density-based algorithm for discovering clusters in large spatial databases with noise. In Proceedings of the Second International Conference on Knowledge Discovery and Data Mining (KDD-96) (pp. 226-231). AAAI Press.

[10] Cooley, J. W., & Tukey, J. W. (1965). An algorithm for the machine calculation of complex Fourier series. Mathematics of Computation, 19(90), 297-301. https://doi.org/10.1090/S0025-5718-1965-0178586-1

[11] Randall, R. B., & Antoni, J. (2011). Rolling element bearing diagnostics: A tutorial. Mechanical Systems and Signal Processing, 25(2), 485-520. https://doi.org/10.1016/j.ymssp.2010.07.017

[12] Smith, W. A., & Randall, R. B. (2015). Rolling element bearing diagnostics using the Case Western Reserve University data: A benchmark study. Mechanical Systems and Signal Processing, 64-65, 100-131. https://doi.org/10.1016/j.ymssp.2015.04.021

[13] Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation forest. In 2008 Eighth IEEE International Conference on Data Mining (pp. 413-422). https://doi.org/10.1109/ICDM.2008.17

[14] Lei, Y., Yang, B., Jiang, X., Jia, F., Li, N., & Nandi, A. K. (2020). Applications of machine learning to machine fault diagnosis: A review and roadmap. Mechanical Systems and Signal Processing, 138, 106587. https://doi.org/10.1016/j.ymssp.2019.106587