Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shape Classification Evan Toler CAAM 210.

Similar presentations


Presentation on theme: "Shape Classification Evan Toler CAAM 210."β€” Presentation transcript:

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


Download ppt "Shape Classification Evan Toler CAAM 210."

Similar presentations


Ads by Google