Presentation is loading. Please wait.

Presentation is loading. Please wait.

軟體實作與計算實驗 1 Lecture 9 Classification Two mappings from position to color Linear combination of distances to centers RBF: Linear combination of exponential.

Similar presentations


Presentation on theme: "軟體實作與計算實驗 1 Lecture 9 Classification Two mappings from position to color Linear combination of distances to centers RBF: Linear combination of exponential."— Presentation transcript:

1 軟體實作與計算實驗 1 Lecture 9 Classification Two mappings from position to color Linear combination of distances to centers RBF: Linear combination of exponential distances to centers Four computational steps (A) K-means (B) Cross Distances (C) Optimal Coefficients (D) Coloring Five flow charts: OC (optimal coefficients), Coloring, ER (error rate), TRAINING & TESTING :

2 軟體實作與計算實驗 2 Kmeans: Data and MATLAB codes data_9.zip demo_kmeans.m load data_9.mat plot(X(:,1),X(:,2),'.'); [cidx, Y] = kmeans(X,10); hold on; plot(Y(:,1),Y(:,2),'ro');

3 軟體實作與計算實驗 3 My_kmeans: Data and MATLAB codes data_9.zip demo_my_kmeans.m my_kmeans.m load data_9.mat plot(X(:,1),X(:,2),'.'); [Y] = my_kmeans(X,10); hold on; plot(Y(:,1),Y(:,2),'ro');

4 軟體實作與計算實驗 4 ClusteringTest.rar my_kmeans.m GUI

5 軟體實作與計算實驗 5

6 6 Path of 4 means to centers of clusters

7 軟體實作與計算實驗 7 Tracking Convergence of K means

8 軟體實作與計算實驗 8 Path to converge data_2c.zip

9 軟體實作與計算實驗 9 Color points A color point POSITION COLOR A mapping from position to color

10 軟體實作與計算實驗 10 Classification of color points A mapping from position to color A rule for discriminating red points from blue points

11 軟體實作與計算實驗 11 A mapping from position to color Each point has its membership to partitioned regions Blue points and red points are well separated A mathematical mapping NO TABLE LOOK-UP !!

12 軟體實作與計算實驗 12 load data_2c.mat data_2c.zip X=data_2c(:,1:2); Y=data_2c(:,3); X : positions of points Y : 0 or 1 ( blue or red color) Color points

13 軟體實作與計算實驗 13 Two-dimensional color points Load data for classification function show_color_data(X,Y) figure; ind = find(Y==0); plot(X(ind,1), X(ind,2), 'b. '); hold on ind = find(Y==1); plot(X(ind,1), X(ind,2), 'r.') load data_2c X=data_2c(:,1:2); Y=data_2c(:,3); show_color_data(X,Y)

14 軟體實作與計算實驗 14 Position & Color X and Y are paired data X collects positions of points Y collects colors of points A mapping from position to color is derived for classification of color points

15 軟體實作與計算實驗 15 Sampling for training Sampling one half as training points N=size(X,1); ind=randperm(N); n = floor(N/2); x_train=X(ind(1:n),:); y_train=Y(ind(1:n),:); show_color_data(x_train,y_train)

16 軟體實作與計算實驗 16 X and Y Sampling x_train and y_train Sampling for training n=N/2

17 軟體實作與計算實驗 17 x_train and y_train OC(optimal coefficients) STEPS A,B,C TRAINING STEP D: coloring x_trainy_haty_train ER (error rate) Error rate for training ½ data centers, a

18 軟體實作與計算實驗 18 X and Y TESTING STEP D: coloring XY_hatY ER (error rate) Error rate for training centers, a All data

19 軟體實作與計算實驗 19 Lower error rate for better testing Error Rate A mapping X All data

20 軟體實作與計算實驗 20 Linear cut load data_2c.txt error rate : zero

21 軟體實作與計算實驗 21 Linear cut x1x1 x2x2

22 軟體實作與計算實驗 22 Linear cut fails load data_3c.txt error rate : 0.289

23 軟體實作與計算實驗 23 Computations STEP A: kmeans Apply K-means to find K centers STEP B: cross distances Calculate cross distances between K means and N data points STEP C: optimal coefficients Determine a mapping from position to color

24 軟體實作與計算實驗 24 Sampling of training data data_3c.zip load data_3c X=data_3c(:,1:2); Y=data_3c(:,3); N=size(X,1); ind=randperm(N); n=floor(N/2); x_train=X(ind(1:n),:); y_train=Y(ind(1:n),:); show_color_data(x_train, y_train)

25 軟體實作與計算實驗 25 Step A K-means

26 軟體實作與計算實驗 26 centers = my_kmeans(x_train,3);

27 軟體實作與計算實驗 27 Step B Distances between centers and data points D(i,j) stores the distance between the ith point and the jth center D = cross_distance(x_train,centers) cross_distance.m

28 軟體實作與計算實驗 28 Step C: optimal coefficients Linear combination of distances to centers x … … a1a1 akak aKaK sum

29 軟體實作與計算實驗 29 A mapping for coloring (mapping I)

30 軟體實作與計算實驗 30 Coloring one point

31 軟體實作與計算實驗 31

32 軟體實作與計算實驗 32

33 軟體實作與計算實驗 33 STEP D: Coloring n points

34 軟體實作與計算實驗 34 STEP C: Optimal coefficients

35 軟體實作與計算實驗 35 Flow chart I : Optimal coefficients centers = my_kmeans(x_train,3 ); D = cross_distance(x_train,centers) x_train, y_train a = pinv(D)*y_train; centers, a STEP A STEP B STEP C funtion [centers,a]=OC(x_train,y_train)

36 軟體實作與計算實驗 36 x_train, centers, a y_hat=D*a; Flow chart II : coloring D = cross_distance(x_train,centers) STEP D coloring y_hat function y_hat=coloring(x_train,centers,a) STEP B

37 軟體實作與計算實驗 37 y_hat,y_train e=abs(y_train-round(y_hat)); n= length(y_train); er=sum(e)/n Error rate ans = 0 Flow chart III: Error rate for training function er=err_rate(y_hat,y_train)

38 軟體實作與計算實驗 38 Flow chart IV : TRAINING [centers,a]=OC(x_train,y_train) y_hat=coloring(x_train,centers,a) er=err_rate(y_hat,y_train) x_train,y_train er FLOW CHART I FLOW CHART II FLOW CHART III

39 軟體實作與計算實驗 39 Flow Chart V: TESTING load data_3c X=data_3c(:,1:2); Y=data_3c(:,3); Error rate ans = 0.026 y_hat=coloring(x_train,centers,a) er=err_rate(y_hat,y_train) centers,a FLOW CHART II FLOW CHART III

40 軟體實作與計算實驗 40 Mapping II from position to color x … … a1a1 akak aKaK sum Linear combination of exponential distances to centers

41 軟體實作與計算實驗 41 Discriminating rule

42 軟體實作與計算實驗 42

43 軟體實作與計算實驗 43 Set all variances to h for simplicity Step D: Coloring

44 軟體實作與計算實驗 44 Optimal coefficients

45 軟體實作與計算實驗 45 Flow chart I : Optimal coefficients centers = my_kmeans(x_train,3 ); D = cross_distance(x_train,centers) x_train, y_train h=200; a = pinv(exp(-D/h))*Y_TRAIN; centers, a STEP A STEP B STEP C funtion [centers,a]=OC(x_train,y_train)

46 軟體實作與計算實驗 46 x_train, centers, a y_hat=exp(-D/h)*a; Flow chart II : coloring D = cross_distance(x_train,centers) STEP D coloring Y_hat function y_hat=coloring(x_train,centers,a) STEP B

47 軟體實作與計算實驗 47 y_hat,y_train e=abs(y_train-round(y_hat)); n= length(y_train); er=sum(e)/n Error rate ans = 0 Flow chart III: Error rate for training function er=err_rate(y_hat,y_train)

48 軟體實作與計算實驗 48 Flow chart IV: TRAINING [centers,a]=OC(x_train,y_train) y_hat=coloring(x_train,centers,a) er=err_rate(y_hat,y_train) x_train,y_train er FLOW CHART I FLOW CHART II FLOW CHART III

49 軟體實作與計算實驗 49 Flow Chart V: TESTING load data_3c X=data_3c(:,1:2); Y=data_3c(:,3); y_hat=coloring(x_train,centers,a) er=err_rate(y_hat,y_train) Error rate ans = 0.000 centers,a FLOW CHART II FLOW CHART III


Download ppt "軟體實作與計算實驗 1 Lecture 9 Classification Two mappings from position to color Linear combination of distances to centers RBF: Linear combination of exponential."

Similar presentations


Ads by Google