Download presentation
Presentation is loading. Please wait.
1
Shape Classification Evan Toler CAAM 210
2
A shape is⦠A shape/curve is a list of points
e.g. (x1, y1), (x2, y2), β¦ x and y are both functions of time, t Build this into a matrix with two rows: π₯( π‘ 1 ) π₯( π‘ 2 ) β¦ π₯( π‘ π ) π¦( π‘ 1 ) π¦ π‘ 2 β¦ π¦( π‘ π ) β β 2Γπ
3
Storing many shapes It will be helpful to store many different curves in one data structure Solution: 3-D array! Let πΆβ β 2ΓπΓπ π = number of points per curve π = number of curves C(:, :, i) is a 2xn matrix representing the π π‘β curve Think: βsheetsβ of curves
4
Generating Random Open Curves
Creating one curve: Take a function handle, say f(x) = cos(x) Given an input vector t, form the matrix πΆ 1 = π₯( π‘ 1 ) π₯ π‘ β¦ π₯( π‘ π ) π(π₯ π‘ 1 ) π(π₯ π‘ 2 ) β¦ π(π₯ π‘ π ) = π₯ π π₯ Pollute each element of C_1 with random noise: randn(2,n)*0.05 Center the rows of C_1 (subtract the means) Scale C_1 with respect to the Frobenius norm: norm(C_1,βfroβ) Intuition: shapes are invariant under translation and scaling Same idea behind unit vectors i, j, k
5
Distances between curves
follow the PDF πππ π‘(πΆ1, πΆ2) = the frobenius norm of (πΆ1 β πβ
πΆ2) O is built from the SVD of C1*C2^T
6
Testing Open Curves Framework:
Take function handles cos(), sin(), x.^2, x For each handle, generate 10 random, polluted curves (total of 40 curves) Create the matrix of pairwise distances between each of the curves (40x40 matrix) Generate 100 new curves and report the success rate for classification.
7
Classifying Open Curves
Letβs say you have p curves, and you know the shape of each of them Given a new, unknown curve, letβs decide what shape it should be. Step 1: Pick a random function handle. Step 2: Generate a random, polluted curve from that function handle. Step 3: Compute the distance from the random curve to each of the known curves Get distances π 1 ,β¦, π π Pick the curve with minimum distance to the unknown curve. Classify the unknown curve as this type of function handle. Check and see if your predicted function handle matches the true signal from step 1.
8
Closed Curves What is a closed curve?
Instead of generating random closed curves, we will import some data M = load('DataClassification.matβ); Tr = M.trainingdata; Ts = M.testdata;
9
Distances between Closed Curves
Distance will change depending on the starting and ending points of the curve Solution: try every possible starting point For a given orientation, compute the distance as open curves Try all orientations, and take the minimum distance
10
Classify Closed Curves
The given data has 20 clusters Training data has 15 curves per cluster, for a total of 300 curves Test data has 5 curves per cluster, for a total of 100 curves For each test curve, compute the distances to each of the training curves. As before, take the minimum distance and classify the curve that way
11
Using the Structure of the Data
β¦ β¦ Tr(:,:,30) Ts(:,:,10) β¦ β¦ Tr(:,:,16) Ts(:,:,6) β¦ β¦ Tr(:,:,15) Ts(:,:,5) β¦ β¦ β¦ β¦ Tr(:,:,1) Ts(:,:,1) β¦ β¦ Cluster 1 Cluster 2 Assume test curve 7 is closest to training curve 25. How can you tell if the classification is correct? Look at (a variation of) 7/5 and 25/15. Both correspond to cluster 2.
12
Clustering Unsupervised Learning: sort the curves into clusters without any knowledge of other curves Compute the pairwise distance matrix between all of the curves Make sure to center and scale! Take the lower triangular part (w/o the diagonal) and feed these distances to linkage() Make a long distance vector Cluster into 6 groups using cluster() and report which curves are classified where
13
Challenge: K Nearest Neighbors
This lab: K Nearest neighbors with K=1 Now, ramp up the noise to randn(2,n) * 0.7 Implement K Nearest Neighbors Concept of majority vote Take K = 1, 2, 3, β¦, # of training curves Plot Error vs. K Include both training error and test error
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.