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 Four class case: \omega_1 , \omega_2 , \omega_3 and \omega_4 with p(x|\omega_k) = \left| 2 \pi \mathbf{\Sigma}_k \right|^{-\frac{1}{2}} e^{-\frac{1}{2} \left( \mathbf{x} – \mathbf{\mu}_k \right)^{t} \mathbf{\Sigma}_k\!^{-1} \left( \mathbf{x} – \mathbf{\mu}_k \right) } with \mathbf{\mu}_1 = \left[ \begin{array}{c} 1 \\ 1 \\ 0 \\ 0 \end{array} \right] , \mathbf{\mu}_2 = \left[ \begin{array}{c} 0 \\ 1 \\ 1 \\ 0 \end{array} \right] , \mathbf{\mu}_3 = \left[ \begin{array}{c} 0 \\ 0 \\ 1 \\ 1 \end{array} \right] , \mathbf{\mu}_4 = \left[ \begin{array}{c} 1 \\ 1 \\ 1 \\ 1 \end{array} \right] , and \mathbf{\Sigma}_k =
k \sigma\!^2 \mathbf{\Sigma} . Define log Guassian function for later evaluation logGauss = @(x,mu,Sigma) -0.5 * log(det(2*pi*Sigma)) -0.5*dot((x-mu),(Sigma\(x-mu)));
logGauss1 = @(x,mu,Sigma) -0.5 * log(abs(2*pi*Sigma)) – 0.5*((x-mu).^2)/Sigma; Generate N samples of the two classes: N = 1e6;
sigma2 = 0.05;
Sigma = [ 2 , 0.5 , 0 , 0 ; …
0.5 , 1 , 0 , 0 ; …
0 , 0 , 4 , 0 ; …
0 , 0 , 0 , 7.5 ];

SqrtSigma = chol(sigma2*Sigma); Dimension of Measurments dim = 4; Number of dimensions to reduce to: dim_red = 4 is no reduction dim_red = 1 is reducing from 4 dimenions (all available dimensions) to just 1 dimension. dim_red = 4;
mu1 = [ 1 ; 1 ; 0 ; 0 ];
mu2 = [ 0 ; 1 ; 1 ; 0 ];
mu3 = [ 0 ; 0 ; 1 ; 1 ];
mu4 = [ 1 ; 1 ; 1 ; 1 ];
Sigma1 = sigma2 * Sigma;
Sigma2 = sigma2 * 2 * Sigma;
Sigma3 = sigma2 * 3 * Sigma;
Sigma4 = sigma2 * 4 * Sigma;

x1 = mu1 + SqrtSigma * randn(dim,N);
x2 = mu2 + sqrt( 2 ) * SqrtSigma * randn(dim,N);
x3 = mu3 + sqrt( 3 ) * SqrtSigma * randn(dim,N);
x4 = mu4 + sqrt( 4 ) * SqrtSigma * randn(dim,N); Without any dimensional reduction, deterimine discriminant functions and determine error rate: tic;
d11_RAW = logGauss(x1,mu1,Sigma1);
d12_RAW = logGauss(x1,mu2,Sigma2);
d13_RAW = logGauss(x1,mu3,Sigma3);
d14_RAW = logGauss(x1,mu4,Sigma4);
d21_RAW = logGauss(x2,mu1,Sigma1);
d22_RAW = logGauss(x2,mu2,Sigma2);
d23_RAW = logGauss(x2,mu3,Sigma3);
d24_RAW = logGauss(x2,mu4,Sigma4);
d31_RAW = logGauss(x3,mu1,Sigma1);
d32_RAW = logGauss(x3,mu2,Sigma2);
d33_RAW = logGauss(x3,mu3,Sigma3);
d34_RAW = logGauss(x3,mu4,Sigma4);
d41_RAW = logGauss(x4,mu1,Sigma1);
d42_RAW = logGauss(x4,mu2,Sigma2);
d43_RAW = logGauss(x4,mu3,Sigma3);
d44_RAW = logGauss(x4,mu4,Sigma4);
Error computation. error1_RAW = sum( d11_RAW < max( [ d11_RAW ; d12_RAW ; d13_RAW ; d14_RAW ] ) ); error2_RAW = sum( d22_RAW < max( [ d21_RAW ; d22_RAW ; d23_RAW ; d24_RAW ] ) ); error3_RAW = sum( d33_RAW < max( [ d31_RAW ; d32_RAW ; d33_RAW ; d34_RAW ] ) ); error4_RAW = sum( d44_RAW < max( [ d41_RAW ; d42_RAW ; d43_RAW ; d44_RAW ] ) ); time_raw = toc error_RAW = ( error1_RAW + error2_RAW + error3_RAW + error4_RAW )/(4*N) Now perform PCA to reduce to one dimension and see how the error is changed. combined_data = zeros( dim , 4*N ); combined_data( : , 1 : N ) = x1; combined_data( : , N+1 : 2*N ) = x2; combined_data( : , 2*N+1 : 3*N ) = x3; combined_data( : , 3*N+1 : 4*N ) = x4; Find mean and covariance of whole data set. mean_total = mean( combined_data , 2); cov_total = cov( combined_data.' ).'; Perform SVD to identify basis vectors for linear subspaces with most of the signal power. [U,D,V] = svd( cov_total ); Find column vectors identifying basis vectors for subspace we wish to keep. U_PCA = U(:,1:dim_red); Start timing tic; Perform PCA dimension reduction for dataset of each class. x1_PCA = U_PCA' * x1; x2_PCA = U_PCA' * x2; x3_PCA = U_PCA' * x3; x4_PCA = U_PCA' * x4; Find mean for each dimensionally reduced dataset. mu1_PCA = U_PCA' * mu1; mu2_PCA = U_PCA' * mu2; mu3_PCA = U_PCA' * mu3; mu4_PCA = U_PCA' * mu4; Find Covariance of dimensionally reduced dataset. Sigma1_PCA = U_PCA' * Sigma1 * U_PCA; Sigma2_PCA = U_PCA' * Sigma2 * U_PCA; Sigma3_PCA = U_PCA' * Sigma3 * U_PCA; Sigma4_PCA = U_PCA' * Sigma4 * U_PCA; Perform classification on PCA dimensionally reduced datasets if dim_red > 1
d11_PCA = logGauss(x1_PCA,mu1_PCA,Sigma1_PCA);
d12_PCA = logGauss(x1_PCA,mu2_PCA,Sigma2_PCA);
d13_PCA = logGauss(x1_PCA,mu3_PCA,Sigma3_PCA);
d14_PCA = logGauss(x1_PCA,mu4_PCA,Sigma4_PCA);
d21_PCA = logGauss(x2_PCA,mu1_PCA,Sigma1_PCA);
d22_PCA = logGauss(x2_PCA,mu2_PCA,Sigma2_PCA);
d23_PCA = logGauss(x2_PCA,mu3_PCA,Sigma3_PCA);
d24_PCA = logGauss(x2_PCA,mu4_PCA,Sigma4_PCA);
d31_PCA = logGauss(x3_PCA,mu1_PCA,Sigma1_PCA);
d32_PCA = logGauss(x3_PCA,mu2_PCA,Sigma2_PCA);
d33_PCA = logGauss(x3_PCA,mu3_PCA,Sigma3_PCA);
d34_PCA = logGauss(x3_PCA,mu4_PCA,Sigma4_PCA);
d41_PCA = logGauss(x4_PCA,mu1_PCA,Sigma1_PCA);
d42_PCA = logGauss(x4_PCA,mu2_PCA,Sigma2_PCA);
d43_PCA = logGauss(x4_PCA,mu3_PCA,Sigma3_PCA);
d44_PCA = logGauss(x4_PCA,mu4_PCA,Sigma4_PCA);
else
d11_PCA = logGauss1(x1_PCA,mu1_PCA,Sigma1_PCA);
d12_PCA = logGauss1(x1_PCA,mu2_PCA,Sigma2_PCA);
d13_PCA = logGauss1(x1_PCA,mu3_PCA,Sigma3_PCA);
d14_PCA = logGauss1(x1_PCA,mu4_PCA,Sigma4_PCA);
d21_PCA = logGauss1(x2_PCA,mu1_PCA,Sigma1_PCA);
d22_PCA = logGauss1(x2_PCA,mu2_PCA,Sigma2_PCA);
d23_PCA = logGauss1(x2_PCA,mu3_PCA,Sigma3_PCA);
d24_PCA = logGauss1(x2_PCA,mu4_PCA,Sigma4_PCA);
d31_PCA = logGauss1(x3_PCA,mu1_PCA,Sigma1_PCA);
d32_PCA = logGauss1(x3_PCA,mu2_PCA,Sigma2_PCA);
d33_PCA = logGauss1(x3_PCA,mu3_PCA,Sigma3_PCA);
d34_PCA = logGauss1(x3_PCA,mu4_PCA,Sigma4_PCA);
d41_PCA = logGauss1(x4_PCA,mu1_PCA,Sigma1_PCA);
d42_PCA = logGauss1(x4_PCA,mu2_PCA,Sigma2_PCA);
d43_PCA = logGauss1(x4_PCA,mu3_PCA,Sigma3_PCA);
d44_PCA = logGauss1(x4_PCA,mu4_PCA,Sigma4_PCA);
end Error computation. error1_PCA = sum( d11_PCA < max( [ d11_PCA ; d12_PCA ; d13_PCA ; d14_PCA ] ) ); error2_PCA = sum( d22_PCA < max( [ d21_PCA ; d22_PCA ; d23_PCA ; d24_PCA ] ) ); error3_PCA = sum( d33_PCA < max( [ d31_PCA ; d32_PCA ; d33_PCA ; d34_PCA ] ) ); error4_PCA = sum( d44_PCA < max( [ d41_PCA ; d42_PCA ; d43_PCA ; d44_PCA ] ) ); time_PCA = toc error_PCA = ( error1_PCA + error2_PCA + error3_PCA + error4_PCA )/(4*N) Now, we will look at the Fisher Linear Discriminant to see how it changes the operation Compute the In-class scatter matrices delta_1 = x1 - mu1; delta_2 = x2 - mu2; delta_3 = x3 - mu3; delta_4 = x4 - mu4; S1 = delta_1 * delta_1'; S2 = delta_2 * delta_2'; S3 = delta_3 * delta_3'; S4 = delta_4 * delta_4'; SW = S1 + S2 + S3 + S4; Calculate the between-class scatter matrix mean1 = mean( x1 , 2 ); mean2 = mean( x2 , 2 ); mean3 = mean( x3 , 2 ); mean4 = mean( x4 , 2 ); deltam_1 = N * ( ( mean1 - mean_total ) * ( mean1 - mean_total )' ); deltam_2 = N * ( ( mean2 - mean_total ) * ( mean2 - mean_total )' ); deltam_3 = N * ( ( mean3 - mean_total ) * ( mean3 - mean_total )' ); deltam_4 = N * ( ( mean4 - mean_total ) * ( mean4 - mean_total )' ); SB = deltam_1 + deltam_2 + deltam_3 + deltam_4; Solve generalized eigenvalue problem [ Vfld , Dfld ] = eig( SB , SW ); Keep the number of dimensions desired. Keep the dimensions corresponding to highest eigenvalues. [ ~ , idx_eig ] = sort( diag(Dfld) , 'descend' ); idx_keep = idx_eig( 1 : dim_red ); w_FLD = Vfld(: , idx_keep ); Compute the dimensionally reduced mean and covariances for each class mu1_FLD = w_FLD' * mu1; mu2_FLD = w_FLD' * mu2; mu3_FLD = w_FLD' * mu3; mu4_FLD = w_FLD' * mu4; Sigma1_FLD = w_FLD' * Sigma1 * w_FLD; Sigma2_FLD = w_FLD' * Sigma2 * w_FLD; Sigma3_FLD = w_FLD' * Sigma3 * w_FLD; Sigma4_FLD = w_FLD' * Sigma4 * w_FLD; Start timing tic; Compute the FLD dimensionally reduced measurment vectors for each class x1_FLD = w_FLD' * x1; x2_FLD = w_FLD' * x2; x3_FLD = w_FLD' * x3; x4_FLD = w_FLD' * x4; Compute the discriminant functions if dim_red > 1
d11_FLD = logGauss(x1_FLD,mu1_FLD,Sigma1_FLD);
d12_FLD = logGauss(x1_FLD,mu2_FLD,Sigma2_FLD);
d13_FLD = logGauss(x1_FLD,mu3_FLD,Sigma3_FLD);
d14_FLD = logGauss(x1_FLD,mu4_FLD,Sigma4_FLD);
d21_FLD = logGauss(x2_FLD,mu1_FLD,Sigma1_FLD);
d22_FLD = logGauss(x2_FLD,mu2_FLD,Sigma2_FLD);
d23_FLD = logGauss(x2_FLD,mu3_FLD,Sigma3_FLD);
d24_FLD = logGauss(x2_FLD,mu4_FLD,Sigma4_FLD);
d31_FLD = logGauss(x3_FLD,mu1_FLD,Sigma1_FLD);
d32_FLD = logGauss(x3_FLD,mu2_FLD,Sigma2_FLD);
d33_FLD = logGauss(x3_FLD,mu3_FLD,Sigma3_FLD);
d34_FLD = logGauss(x3_FLD,mu4_FLD,Sigma4_FLD);
d41_FLD = logGauss(x4_FLD,mu1_FLD,Sigma1_FLD);
d42_FLD = logGauss(x4_FLD,mu2_FLD,Sigma2_FLD);
d43_FLD = logGauss(x4_FLD,mu3_FLD,Sigma3_FLD);
d44_FLD = logGauss(x4_FLD,mu4_FLD,Sigma4_FLD);
else
d11_FLD = logGauss1(x1_FLD,mu1_FLD,Sigma1_FLD);
d12_FLD = logGauss1(x1_FLD,mu2_FLD,Sigma2_FLD);
d13_FLD = logGauss1(x1_FLD,mu3_FLD,Sigma3_FLD);
d14_FLD = logGauss1(x1_FLD,mu4_FLD,Sigma4_FLD);
d21_FLD = logGauss1(x2_FLD,mu1_FLD,Sigma1_FLD);
d22_FLD = logGauss1(x2_FLD,mu2_FLD,Sigma2_FLD);
d23_FLD = logGauss1(x2_FLD,mu3_FLD,Sigma3_FLD);
d24_FLD = logGauss1(x2_FLD,mu4_FLD,Sigma4_FLD);
d31_FLD = logGauss1(x3_FLD,mu1_FLD,Sigma1_FLD);
d32_FLD = logGauss1(x3_FLD,mu2_FLD,Sigma2_FLD);
d33_FLD = logGauss1(x3_FLD,mu3_FLD,Sigma3_FLD);
d34_FLD = logGauss1(x3_FLD,mu4_FLD,Sigma4_FLD);
d41_FLD = logGauss1(x4_FLD,mu1_FLD,Sigma1_FLD);
d42_FLD = logGauss1(x4_FLD,mu2_FLD,Sigma2_FLD);
d43_FLD = logGauss1(x4_FLD,mu3_FLD,Sigma3_FLD);
d44_FLD = logGauss1(x4_FLD,mu4_FLD,Sigma4_FLD);
end Error computation. error1_FLD = sum( d11_FLD < max( [ d11_FLD ; d12_FLD ; d13_FLD ; d14_FLD ] ) ); error2_FLD = sum( d22_FLD < max( [ d21_FLD ; d22_FLD ; d23_FLD ; d24_FLD ] ) ); error3_FLD = sum( d33_FLD < max( [ d31_FLD ; d32_FLD ; d33_FLD ; d34_FLD ] ) ); error4_FLD = sum( d44_FLD < max( [ d41_FLD ; d42_FLD ; d43_FLD ; d44_FLD ] ) ); time_FLD = toc error_FLD = ( error1_FLD + error2_FLD + error3_FLD + error4_FLD )/(4*N) manual document ready 0.4 variable time_raw 1.8514 1 1 48 variable error_RAW 0.1664 1 1 49 variable time_PCA 2.1740 1 1 112 variable error_PCA 0.1664 1 1 113 variable time_FLD 2.3446 1 1 198 variable error_FLD 0.1664 1 1 199 true false logGauss = @(x,mu,Sigma) -0.5 * log(det(2*pi*Sigma)) -0.5*dot((x-mu),(Sigma\(x-mu))); 0 5 5 false false logGauss1 = @(x,mu,Sigma) -0.5 * log(abs(2*pi*Sigma)) - 0.5*((x-mu).^2)/Sigma; 1 6 6 false false N = 1e6; 2 8 8 false false sigma2 = 0.05; 3 9 9 false false Sigma = [ 2 , 0.5 , 0 , 0 ; ... 0.5 , 1 , 0 , 0 ; ... 0 , 0 , 4 , 0 ; ... 0 , 0 , 0 , 7.5 ]; 4 10 13 false false SqrtSigma = chol(sigma2*Sigma); 5 15 15 false false dim = 4; 6 17 17 false false dim_red = 4; 7 20 20 false false mu1 = [ 1 ; 1 ; 0 ; 0 ]; 8 21 21 false false mu2 = [ 0 ; 1 ; 1 ; 0 ]; 9 22 22 false false mu3 = [ 0 ; 0 ; 1 ; 1 ]; 10 23 23 false false mu4 = [ 1 ; 1 ; 1 ; 1 ]; 11 24 24 false false Sigma1 = sigma2 * Sigma; 12 25 25 false false Sigma2 = sigma2 * 2 * Sigma; 13 26 26 false false Sigma3 = sigma2 * 3 * Sigma; 14 27 27 false false Sigma4 = sigma2 * 4 * Sigma; 15 28 28 false false x1 = mu1 + SqrtSigma * randn(dim,N); 16 30 30 false false x2 = mu2 + sqrt( 2 ) * SqrtSigma * randn(dim,N); 17 31 31 false false x3 = mu3 + sqrt( 3 ) * SqrtSigma * randn(dim,N); 18 32 32 false false x4 = mu4 + sqrt( 4 ) * SqrtSigma * randn(dim,N); 19 33 33 false false tic; 20 35 35 false false d11_RAW = logGauss(x1,mu1,Sigma1); 21 36 36 false false d12_RAW = logGauss(x1,mu2,Sigma2); 22 37 37 false false d13_RAW = logGauss(x1,mu3,Sigma3); 23 38 38 false false d14_RAW = logGauss(x1,mu4,Sigma4); 24 39 39 false false d21_RAW = logGauss(x2,mu1,Sigma1); 25 40 40 false false d22_RAW = logGauss(x2,mu2,Sigma2); 26 41 41 false false d23_RAW = logGauss(x2,mu3,Sigma3); 27 42 42 false false d24_RAW = logGauss(x2,mu4,Sigma4); 28 43 43 false false d31_RAW = logGauss(x3,mu1,Sigma1); 29 44 44 false false d32_RAW = logGauss(x3,mu2,Sigma2); 30 45 45 false false d33_RAW = logGauss(x3,mu3,Sigma3); 31 46 46 false false d34_RAW = logGauss(x3,mu4,Sigma4); 32 47 47 false false d41_RAW = logGauss(x4,mu1,Sigma1); 33 48 48 false false d42_RAW = logGauss(x4,mu2,Sigma2); 34 49 49 false false d43_RAW = logGauss(x4,mu3,Sigma3); 35 50 50 false false d44_RAW = logGauss(x4,mu4,Sigma4); 36 51 51 false false error1_RAW = sum( d11_RAW < max( [ d11_RAW ; d12_RAW ; d13_RAW ; d14_RAW ] ) ); 37 54 54 false false error2_RAW = sum( d22_RAW < max( [ d21_RAW ; d22_RAW ; d23_RAW ; d24_RAW ] ) ); 38 55 55 false false error3_RAW = sum( d33_RAW < max( [ d31_RAW ; d32_RAW ; d33_RAW ; d34_RAW ] ) ); 39 56 56 false false error4_RAW = sum( d44_RAW < max( [ d41_RAW ; d42_RAW ; d43_RAW ; d44_RAW ] ) ); 40 57 57 false false time_raw = toc 41 58 58 0 false false error_RAW = ( error1_RAW + error2_RAW + error3_RAW + error4_RAW )/(4*N) 42 59 59 1 false false combined_data = zeros( dim , 4*N ); 43 61 61 false false combined_data( : , 1 : N ) = x1; 44 62 62 false false combined_data( : , N+1 : 2*N ) = x2; 45 63 63 false false combined_data( : , 2*N+1 : 3*N ) = x3; 46 64 64 false false combined_data( : , 3*N+1 : 4*N ) = x4; 47 65 65 false false mean_total = mean( combined_data , 2); 48 68 68 false false cov_total = cov( combined_data.' ).'; 49 69 69 false false [U,D,V] = svd( cov_total ); 50 71 71 false false U_PCA = U(:,1:dim_red); 51 73 73 false false tic; 52 75 75 false false x1_PCA = U_PCA' * x1; 53 77 77 false false x2_PCA = U_PCA' * x2; 54 78 78 false false x3_PCA = U_PCA' * x3; 55 79 79 false false x4_PCA = U_PCA' * x4; 56 80 80 false false mu1_PCA = U_PCA' * mu1; 57 82 82 false false mu2_PCA = U_PCA' * mu2; 58 83 83 false false mu3_PCA = U_PCA' * mu3; 59 84 84 false false mu4_PCA = U_PCA' * mu4; 60 85 85 false false Sigma1_PCA = U_PCA' * Sigma1 * U_PCA; 61 87 87 false false Sigma2_PCA = U_PCA' * Sigma2 * U_PCA; 62 88 88 false false Sigma3_PCA = U_PCA' * Sigma3 * U_PCA; 63 89 89 false false Sigma4_PCA = U_PCA' * Sigma4 * U_PCA; 64 90 90 false false if dim_red > 1
d11_PCA = logGauss(x1_PCA,mu1_PCA,Sigma1_PCA);
d12_PCA = logGauss(x1_PCA,mu2_PCA,Sigma2_PCA);
d13_PCA = logGauss(x1_PCA,mu3_PCA,Sigma3_PCA);
d14_PCA = logGauss(x1_PCA,mu4_PCA,Sigma4_PCA);
d21_PCA = logGauss(x2_PCA,mu1_PCA,Sigma1_PCA);
d22_PCA = logGauss(x2_PCA,mu2_PCA,Sigma2_PCA);
d23_PCA = logGauss(x2_PCA,mu3_PCA,Sigma3_PCA);
d24_PCA = logGauss(x2_PCA,mu4_PCA,Sigma4_PCA);
d31_PCA = logGauss(x3_PCA,mu1_PCA,Sigma1_PCA);
d32_PCA = logGauss(x3_PCA,mu2_PCA,Sigma2_PCA);
d33_PCA = logGauss(x3_PCA,mu3_PCA,Sigma3_PCA);
d34_PCA = logGauss(x3_PCA,mu4_PCA,Sigma4_PCA);
d41_PCA = logGauss(x4_PCA,mu1_PCA,Sigma1_PCA);
d42_PCA = logGauss(x4_PCA,mu2_PCA,Sigma2_PCA);
d43_PCA = logGauss(x4_PCA,mu3_PCA,Sigma3_PCA);
d44_PCA = logGauss(x4_PCA,mu4_PCA,Sigma4_PCA);
else
d11_PCA = logGauss1(x1_PCA,mu1_PCA,Sigma1_PCA);
d12_PCA = logGauss1(x1_PCA,mu2_PCA,Sigma2_PCA);
d13_PCA = logGauss1(x1_PCA,mu3_PCA,Sigma3_PCA);
d14_PCA = logGauss1(x1_PCA,mu4_PCA,Sigma4_PCA);
d21_PCA = logGauss1(x2_PCA,mu1_PCA,Sigma1_PCA);
d22_PCA = logGauss1(x2_PCA,mu2_PCA,Sigma2_PCA);
d23_PCA = logGauss1(x2_PCA,mu3_PCA,Sigma3_PCA);
d24_PCA = logGauss1(x2_PCA,mu4_PCA,Sigma4_PCA);
d31_PCA = logGauss1(x3_PCA,mu1_PCA,Sigma1_PCA);
d32_PCA = logGauss1(x3_PCA,mu2_PCA,Sigma2_PCA);
d33_PCA = logGauss1(x3_PCA,mu3_PCA,Sigma3_PCA);
d34_PCA = logGauss1(x3_PCA,mu4_PCA,Sigma4_PCA);
d41_PCA = logGauss1(x4_PCA,mu1_PCA,Sigma1_PCA);
d42_PCA = logGauss1(x4_PCA,mu2_PCA,Sigma2_PCA);
d43_PCA = logGauss1(x4_PCA,mu3_PCA,Sigma3_PCA);
d44_PCA = logGauss1(x4_PCA,mu4_PCA,Sigma4_PCA);
end 65 92 126 false false error1_PCA = sum( d11_PCA < max( [ d11_PCA ; d12_PCA ; d13_PCA ; d14_PCA ] ) ); 66 128 128 false false error2_PCA = sum( d22_PCA < max( [ d21_PCA ; d22_PCA ; d23_PCA ; d24_PCA ] ) ); 67 129 129 false false error3_PCA = sum( d33_PCA < max( [ d31_PCA ; d32_PCA ; d33_PCA ; d34_PCA ] ) ); 68 130 130 false false error4_PCA = sum( d44_PCA < max( [ d41_PCA ; d42_PCA ; d43_PCA ; d44_PCA ] ) ); 69 131 131 false false time_PCA = toc 70 132 132 2 false false error_PCA = ( error1_PCA + error2_PCA + error3_PCA + error4_PCA )/(4*N) 71 133 133 3 false false delta_1 = x1 - mu1; 72 136 136 false false delta_2 = x2 - mu2; 73 137 137 false false delta_3 = x3 - mu3; 74 138 138 false false delta_4 = x4 - mu4; 75 139 139 false false S1 = delta_1 * delta_1'; 76 141 141 false false S2 = delta_2 * delta_2'; 77 142 142 false false S3 = delta_3 * delta_3'; 78 143 143 false false S4 = delta_4 * delta_4'; 79 144 144 false false SW = S1 + S2 + S3 + S4; 80 146 146 false false mean1 = mean( x1 , 2 ); 81 149 149 false false mean2 = mean( x2 , 2 ); 82 150 150 false false mean3 = mean( x3 , 2 ); 83 151 151 false false mean4 = mean( x4 , 2 ); 84 152 152 false false deltam_1 = N * ( ( mean1 - mean_total ) * ( mean1 - mean_total )' ); 85 154 154 false false deltam_2 = N * ( ( mean2 - mean_total ) * ( mean2 - mean_total )' ); 86 155 155 false false deltam_3 = N * ( ( mean3 - mean_total ) * ( mean3 - mean_total )' ); 87 156 156 false false deltam_4 = N * ( ( mean4 - mean_total ) * ( mean4 - mean_total )' ); 88 157 157 false false SB = deltam_1 + deltam_2 + deltam_3 + deltam_4; 89 159 159 false false [ Vfld , Dfld ] = eig( SB , SW ); 90 162 162 false false [ ~ , idx_eig ] = sort( diag(Dfld) , 'descend' ); 91 164 164 false false idx_keep = idx_eig( 1 : dim_red ); 92 165 165 false false w_FLD = Vfld(: , idx_keep ); 93 166 166 false false mu1_FLD = w_FLD' * mu1; 94 169 169 false false mu2_FLD = w_FLD' * mu2; 95 170 170 false false mu3_FLD = w_FLD' * mu3; 96 171 171 false false mu4_FLD = w_FLD' * mu4; 97 172 172 false false Sigma1_FLD = w_FLD' * Sigma1 * w_FLD; 98 174 174 false false Sigma2_FLD = w_FLD' * Sigma2 * w_FLD; 99 175 175 false false Sigma3_FLD = w_FLD' * Sigma3 * w_FLD; 100 176 176 false false Sigma4_FLD = w_FLD' * Sigma4 * w_FLD; 101 177 177 false false tic; 102 180 180 false false x1_FLD = w_FLD' * x1; 103 182 182 false false x2_FLD = w_FLD' * x2; 104 183 183 false false x3_FLD = w_FLD' * x3; 105 184 184 false false x4_FLD = w_FLD' * x4; 106 185 185 false false if dim_red > 1
d11_FLD = logGauss(x1_FLD,mu1_FLD,Sigma1_FLD);
d12_FLD = logGauss(x1_FLD,mu2_FLD,Sigma2_FLD);
d13_FLD = logGauss(x1_FLD,mu3_FLD,Sigma3_FLD);
d14_FLD = logGauss(x1_FLD,mu4_FLD,Sigma4_FLD);
d21_FLD = logGauss(x2_FLD,mu1_FLD,Sigma1_FLD);
d22_FLD = logGauss(x2_FLD,mu2_FLD,Sigma2_FLD);
d23_FLD = logGauss(x2_FLD,mu3_FLD,Sigma3_FLD);
d24_FLD = logGauss(x2_FLD,mu4_FLD,Sigma4_FLD);
d31_FLD = logGauss(x3_FLD,mu1_FLD,Sigma1_FLD);
d32_FLD = logGauss(x3_FLD,mu2_FLD,Sigma2_FLD);
d33_FLD = logGauss(x3_FLD,mu3_FLD,Sigma3_FLD);
d34_FLD = logGauss(x3_FLD,mu4_FLD,Sigma4_FLD);
d41_FLD = logGauss(x4_FLD,mu1_FLD,Sigma1_FLD);
d42_FLD = logGauss(x4_FLD,mu2_FLD,Sigma2_FLD);
d43_FLD = logGauss(x4_FLD,mu3_FLD,Sigma3_FLD);
d44_FLD = logGauss(x4_FLD,mu4_FLD,Sigma4_FLD);
else
d11_FLD = logGauss1(x1_FLD,mu1_FLD,Sigma1_FLD);
d12_FLD = logGauss1(x1_FLD,mu2_FLD,Sigma2_FLD);
d13_FLD = logGauss1(x1_FLD,mu3_FLD,Sigma3_FLD);
d14_FLD = logGauss1(x1_FLD,mu4_FLD,Sigma4_FLD);
d21_FLD = logGauss1(x2_FLD,mu1_FLD,Sigma1_FLD);
d22_FLD = logGauss1(x2_FLD,mu2_FLD,Sigma2_FLD);
d23_FLD = logGauss1(x2_FLD,mu3_FLD,Sigma3_FLD);
d24_FLD = logGauss1(x2_FLD,mu4_FLD,Sigma4_FLD);
d31_FLD = logGauss1(x3_FLD,mu1_FLD,Sigma1_FLD);
d32_FLD = logGauss1(x3_FLD,mu2_FLD,Sigma2_FLD);
d33_FLD = logGauss1(x3_FLD,mu3_FLD,Sigma3_FLD);
d34_FLD = logGauss1(x3_FLD,mu4_FLD,Sigma4_FLD);
d41_FLD = logGauss1(x4_FLD,mu1_FLD,Sigma1_FLD);
d42_FLD = logGauss1(x4_FLD,mu2_FLD,Sigma2_FLD);
d43_FLD = logGauss1(x4_FLD,mu3_FLD,Sigma3_FLD);
d44_FLD = logGauss1(x4_FLD,mu4_FLD,Sigma4_FLD);
end 107 188 222 false false error1_FLD = sum( d11_FLD < max( [ d11_FLD ; d12_FLD ; d13_FLD ; d14_FLD ] ) ); 108 224 224 false false error2_FLD = sum( d22_FLD < max( [ d21_FLD ; d22_FLD ; d23_FLD ; d24_FLD ] ) ); 109 225 225 false false error3_FLD = sum( d33_FLD < max( [ d31_FLD ; d32_FLD ; d33_FLD ; d34_FLD ] ) ); 110 226 226 false false error4_FLD = sum( d44_FLD < max( [ d41_FLD ; d42_FLD ; d43_FLD ; d44_FLD ] ) ); 111 227 227 false false time_FLD = toc 112 228 228 4 false true error_FLD = ( error1_FLD + error2_FLD + error3_FLD + error4_FLD )/(4*N) 113 229 229 5 2021-03-29T22:55:28Z 2021-04-06T23:18:48Z application/vnd.mathworks.matlab.code MATLAB Code R2019b 9.7.0.1183724 83f044dd-98f4-49be-a174-cb87a6cf6d0b 9.7.0.1471314 R2019b Update 7 Sep 02 2020 3303242823