Clear all;
Close all;
CLC;
Randn ('seed', 0 );
Mu1 = [0 0];
S1 = [0.3 0; 0 0.35];
Cls1_data = mvnrnd (mu1, S1, 1000 );
Plot (cls1_data (:, 1), cls1_data (:, 2), '+ ');
Hold on;
Mu2 = [4 0];
S2 = [1.2 0; 0 1.85];
Cls2_data = mvnrnd (mu2, S2, 1000 );
Plot (cls2_data (:, 1), cls2_data (:, 2), 'r + ');
Axis ([-8 8-8 8]);
For I = -.
For J = -.
D1 = ([I, j]-mu1) * inv (S1) * ([I, j]-mu1 )';
D2 = ([I, j]-mu2) * inv (S2) * ([I, j]-mu2 )';
D = d1-d2;
If D <0.1
Plot (I, j );
End
End
End
Grid on;
Figure;
Mu1 = [0 0];
S1 = [0.1 0; 0 0.75];
Cls1_data = mvnrnd (mu1, S1, 1000 );
Plot (cls1_data (:, 1), cls1_data (:, 2), '+ ');
Hold on;
Mu2 = [3.2 0];
S2 = [0.75 0; 0 0.1];
Cls2_data = mvnrnd (mu2, S2, 1000 );
Plot (cls2_data (:, 1), cls2_data (:, 2), 'r + ');
Axis ([-8 8-8 8]);
For I = -.
For J = -.
D1 = ([I, j]-mu1) * inv (S1) * ([I, j]-mu1 )';
D2 = ([I, j]-mu2) * inv (S2) * ([I, j]-mu2 )';
D = d1-d2;
If D <0.1
Plot (I, j );
End
End
End
Grid on;
Figure;
Mu1 = [0 3];
S1 = [0.3 0; 0 0.35];
Cls1_data = mvnrnd (mu1, S1, 1000 );
Plot (cls1_data (:, 1), cls1_data (:, 2), '+ ');
Hold on;
Mu2 = [4 0];
S2 = [0.3 0; 0 0.35];
Cls2_data = mvnrnd (mu2, S2, 1000 );
Plot (cls2_data (:, 1), cls2_data (:, 2), 'r + ');
Axis ([-8 8-8 8]);
For I = -.
For J = -.
D1 = ([I, j]-mu1) * inv (S1) * ([I, j]-mu1 )';
D2 = ([I, j]-mu2) * inv (S2) * ([I, j]-mu2 )';
D = d1-d2;
If D <0.1
Plot (I, j );
End
End
End
Grid on;
Figure;
Mu1 = [0-3];
S1 = [0.5 1; 1 2.5];
Cls1_data = mvnrnd (mu1, S1, 1000 );
Plot (cls1_data (:, 1), cls1_data (:, 2), '+ ');
Hold on;
Mu2 = [4 0];
S2 = [0.5 1; 1 2.5];
Cls2_data = mvnrnd (mu2, S2, 1000 );
Plot (cls2_data (:, 1), cls2_data (:, 2), 'r + ');
Axis ([-8 8-8 8]);
For I = -.
For J = -.
D1 = ([I, j]-mu1) * inv (S1) * ([I, j]-mu1 )';
D2 = ([I, j]-mu2) * inv (S2) * ([I, j]-mu2 )';
D = d1-d2;
If D <0.1
Plot (I, j );
End
End
End
Grid on;
MATLAB exercise program (normal distribution Bayesian classification)