MATLAB Answers

Hi, i want to calculate the decision boundary in Bayes Estimator. Can anyone help me in this regard.

375 views (last 30 days)
mobeen mahmood
mobeen mahmood on 14 Oct 2017
Edited: Basil Saeed on 5 Jun 2018
clc;
clear;
mu1 = [0 0];
sigma=1;
sigma1 = [2 0; 0 2];
mu2=[1 2];
sigma2 = [1 0;0 1];
x=[-10:.2:9.8];
R1 = chol(sigma1);
R2= chol(sigma2);
W1 = repmat(mu1,100,1) + randn(100,2)*R1;
W2 = repmat(mu2,100,1) + randn(100,2)*R2;
figure
subplot(2,1,1)
plot(x,W1)
hold on
plot(x,W2)
hold off

  0 Comments

Sign in to comment.

Answers (1)

Basil Saeed
Basil Saeed on 5 Jun 2018
Edited: Basil Saeed on 5 Jun 2018
You can find the decision boundary analytically. For Bayesian hypothesis testing, the decision boundary corresponds to the values of X that have equal posteriors, i.e., you need to solve:
for X = (x1, x2).
With equal priors, this decision rule is the same as the likelihood decision rule, i.e.,:
Plugging in the vlaues for the means and covariance matrices and simplifying, you get:
Solving for X:
which implies:
You can also find this numerically with MATLAB and plot it using the following code:
%Natural parameters
mu1 = [0; 0];
sigma1 = [2 0; 0 2];
mu2 = [1; 2];
sigma2 = [1 0; 0 1];
%Gaussians as anonymous functions
gauss1 = @(x1, x2) exp(-0.5*([x1;x2]-mu1)'*sigma1*([x1;x2]-mu1))/(2*pi*sqrt(det(sigma1)));
gauss2 = @(x1, x2) exp(-0.5*([x1;x2]-mu2)'*sigma2*([x1;x2]-mu2))/(2*pi*sqrt(det(sigma2)));
[x1, x2] = meshgrid(-5:0.2:5); %generate grid
g1 = arrayfun(gauss1, x1, x2); %apply functions to grid points
g2 = arrayfun(gauss2, x1, x2);
surf(x1, x2, g1, 'FaceColor', [0.9 0.2 0.2]); %plot
hold on
surf(x1, x2, g2, 'FaceColor', [0.2 0.9 0.2]);
gdiff = g1- g2; %get difference points
C = contours(x1, x2, gdiff, [0,0]); %get points where contour is zero
%get seperate coordinates of contour
x1s = C(1, 2:end);
x2s = C(2, 2:end);
%interporlate contour on gaussian 1
boundry = interp2(x1, x2, g1, x1s, x2s);
%plot it
line(x1s, x2s, boundry, 'Color', 'k', 'LineWidth', 2);

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by