CS计算机代考程序代写 matlab [Content_Types].xml

[Content_Types].xml

_rels/.rels

matlab/document.xml

matlab/output.xml

metadata/coreProperties.xml

metadata/mwcoreProperties.xml

metadata/mwcorePropertiesExtension.xml

metadata/mwcorePropertiesReleaseInfo.xml

Demonstration of PCA and other dimensional reduction Two class case: \omega_1 and \omega_2 with p(x|\omega_1) = \left| 2 \pi \mathbf{\Sigma}_1 \right|^{-\frac{1}{2}} e^{-\frac{1}{2} \left( \mathbf{x} – \mathbf{\mu}_1 \right)^{t} \mathbf{\Sigma}_1\!^{-1} \left( \mathbf{x} – \mathbf{\mu}_1 \right) } with \mathbf{\mu}_1 = \mathbf{0} and \mathbf{\Sigma}_1=\mathbf{I} , with p(x|\omega_2) = \left| 2 \pi \mathbf{\Sigma}_2 \right|^{-\frac{1}{2}} e^{-\frac{1}{2} \left( \mathbf{x} – \mathbf{\mu}_2 \right)^{t} \mathbf{\Sigma}_2\!^{-1} \left( \mathbf{x} – \mathbf{\mu}_2 \right) } with \mathbf{\mu}_2 = \mathbf{1} and \mathbf{\Sigma}_2=\mathbf{I} . Generate N samples of the two classes: N = 1e6;
dim = 2;
mu1 = zeros(dim,1);
mu2 = ones(dim,1);
x1 = mu1 + randn(dim,N);
x2 = mu2 + randn(dim,N); Without any dimensional reduction, deterimine discriminant functions and determine error rate: tic;
d11_RAW = sum( abs(x1 – mu1).^2);
d12_RAW = sum( abs(x1 – mu2).^2);
d21_RAW = sum( abs(x2 – mu1).^2);
d22_RAW = sum( abs(x2 – mu2).^2);

error1_RAW = sum( d12_RAW < d11_RAW ); error2_RAW = sum( d21_RAW < d22_RAW ); time_raw = toc error_RAW = ( error1_RAW + error2_RAW )/(2*N) Now perform PCA to reduce to one dimension and see how the error is changed. combined_data = zeros( dim , 2*N ); combined_data( : , 1 : N ) = x1; combined_data( : , N+1 : 2*N ) = x2; mean_total = mean( combined_data , 2); cov_total = cov( combined_data.' ).'; [U,D,V] = svd( cov_total ); U_PCA = U(:,1); tic; x1_PCA = U_PCA' * x1; x2_PCA = U_PCA' * x2; mu1_PCA = U_PCA' * mu1; mu2_PCA = U_PCA' * mu2; d11_PCA = abs( x1_PCA - mu1_PCA ).^2 ; d12_PCA = abs( x1_PCA - mu2_PCA ).^2 ; d21_PCA = abs( x2_PCA - mu1_PCA ).^2 ; d22_PCA = abs( x2_PCA - mu2_PCA ).^2 ; error1_PCA = sum( d12_PCA < d11_PCA ); error2_PCA = sum( d21_PCA < d22_PCA ); time_PCA = toc error_PCA = ( error1_PCA + error2_PCA )/(2*N) Now, we will look at the Fisher Linear Discriminant to see how it changes the operation delta_1 = x1 - mu1; delta_2 = x2 - mu2; S1 = delta_1 * delta_1'; S2 = delta_2 * delta_2'; Sw = S1 + S2; w_FLD = Sw \ ( mu1 - mu2 ); mu1_FLD = w_FLD' * mu1; mu2_FLD = w_FLD' * mu2; tic; x1_FLD = w_FLD' * x1; x2_FLD = w_FLD' * x2; d11_FLD = abs( x1_FLD - mu1_FLD ).^2; d12_FLD = abs( x1_FLD - mu2_FLD ).^2; d21_FLD = abs( x2_FLD - mu1_FLD ).^2; d22_FLD = abs( x2_FLD - mu2_FLD ).^2; error1_FLD = sum( d12_FLD < d11_FLD ); error2_FLD = sum( d21_FLD < d22_FLD ); time_FLD = toc error_FLD = ( error1_FLD + error2_FLD )/(2*N) manual document ready 0.4 variable time_raw 0.1157 1 1 15 variable error_RAW 0.2402 1 1 16 variable time_PCA 0.0815 1 1 36 variable error_PCA 0.2402 1 1 37 variable time_FLD 0.0994 1 1 56 variable error_FLD 0.2402 1 1 57 true false N = 1e6; 0 6 6 false false dim = 2; 1 7 7 false false mu1 = zeros(dim,1); 2 8 8 false false mu2 = ones(dim,1); 3 9 9 false false x1 = mu1 + randn(dim,N); 4 10 10 false false x2 = mu2 + randn(dim,N); 5 11 11 false false tic; 6 13 13 false false d11_RAW = sum( abs(x1 - mu1).^2); 7 14 14 false false d12_RAW = sum( abs(x1 - mu2).^2); 8 15 15 false false d21_RAW = sum( abs(x2 - mu1).^2); 9 16 16 false false d22_RAW = sum( abs(x2 - mu2).^2); 10 17 17 false false error1_RAW = sum( d12_RAW < d11_RAW ); 11 19 19 false false error2_RAW = sum( d21_RAW < d22_RAW ); 12 20 20 false false time_raw = toc 13 21 21 0 false false error_RAW = ( error1_RAW + error2_RAW )/(2*N) 14 22 22 1 false false combined_data = zeros( dim , 2*N ); 15 24 24 false false combined_data( : , 1 : N ) = x1; 16 25 25 false false combined_data( : , N+1 : 2*N ) = x2; 17 26 26 false false mean_total = mean( combined_data , 2); 18 27 27 false false cov_total = cov( combined_data.' ).'; 19 28 28 false false [U,D,V] = svd( cov_total ); 20 29 29 false false U_PCA = U(:,1); 21 30 30 false false tic; 22 31 31 false false x1_PCA = U_PCA' * x1; 23 32 32 false false x2_PCA = U_PCA' * x2; 24 33 33 false false mu1_PCA = U_PCA' * mu1; 25 34 34 false false mu2_PCA = U_PCA' * mu2; 26 35 35 false false d11_PCA = abs( x1_PCA - mu1_PCA ).^2 ; 27 36 36 false false d12_PCA = abs( x1_PCA - mu2_PCA ).^2 ; 28 37 37 false false d21_PCA = abs( x2_PCA - mu1_PCA ).^2 ; 29 38 38 false false d22_PCA = abs( x2_PCA - mu2_PCA ).^2 ; 30 39 39 false false error1_PCA = sum( d12_PCA < d11_PCA ); 31 41 41 false false error2_PCA = sum( d21_PCA < d22_PCA ); 32 42 42 false false time_PCA = toc 33 43 43 2 false false error_PCA = ( error1_PCA + error2_PCA )/(2*N) 34 44 44 3 false false delta_1 = x1 - mu1; 35 46 46 false false delta_2 = x2 - mu2; 36 47 47 false false S1 = delta_1 * delta_1'; 37 48 48 false false S2 = delta_2 * delta_2'; 38 49 49 false false Sw = S1 + S2; 39 50 50 false false w_FLD = Sw \ ( mu1 - mu2 ); 40 51 51 false false mu1_FLD = w_FLD' * mu1; 41 52 52 false false mu2_FLD = w_FLD' * mu2; 42 53 53 false false tic; 43 55 55 false false x1_FLD = w_FLD' * x1; 44 56 56 false false x2_FLD = w_FLD' * x2; 45 57 57 false false d11_FLD = abs( x1_FLD - mu1_FLD ).^2; 46 58 58 false false d12_FLD = abs( x1_FLD - mu2_FLD ).^2; 47 59 59 false false d21_FLD = abs( x2_FLD - mu1_FLD ).^2; 48 60 60 false false d22_FLD = abs( x2_FLD - mu2_FLD ).^2; 49 61 61 false false error1_FLD = sum( d12_FLD < d11_FLD ); 50 62 62 false false error2_FLD = sum( d21_FLD < d22_FLD ); 51 63 63 false false time_FLD = toc 52 64 64 4 false true error_FLD = ( error1_FLD + error2_FLD )/(2*N) 53 65 65 5 2021-03-29T22:41:19Z 2021-03-29T22:41:19Z application/vnd.mathworks.matlab.code MATLAB Code R2019b 9.7.0.1183724 ba9e748d-e4c7-4047-9fa4-05c33fde8300 9.7.0.1471314 R2019b Update 7 Sep 02 2020 3303242823