Drawing decision boundary of two multivariate gaus

2019-05-28 03:46发布

I am trying to plot something similar to below: enter image description here

I am using Matlab. I achieved drawing contour plots. However I could not draw the discriminant. Can anyone show a sample Matlab code or give some idea to draw the discriminant?

2条回答
劫难
2楼-- · 2019-05-28 04:19

Here is how I would solve this problem analytically: you equate these two discriminant functions

g1(x)=x' W1 x + w1' x + w10
g2(x)=x' W2 x + w2' x + w20
g1(x) = g2(x)

==> x' (W2 - W1) x + (w2-w1)'x + w20 - w10

then, I consider W2 - W1 to have be this matrix

W2-W1 = [a b; c d]

which then by expanding vector x=[x1 x2]', we get:

a x1^2 + (b+c) x1 x2 + d x2^2 + (w21-w11) x1 + (w22-w12) x2 + w20-w10 = 0

this is the equation of an ellipse, so you can simplify it into the form below:

(x1 - a0)^2/h + (x2-b0)^2/g = r^2

Or, you can assume that you know the range of x1 for example x1=[-2:0.1:2], and then solve the parabola

example of a parabolic decision boundary

查看更多
疯言疯语
3楼-- · 2019-05-28 04:24

If you know the probability density function of each of the gaussian for a given point (x,y), lets say its pdf1(x,y) and pdf2(x,y) then you can simply plot the contour line of f(x,y) := pdf1(x,y) > pdf2(x,y). So you define function f to be 1 iff pdf1(x,y)>pdf2(x,y). This way the only contour will be placed along the curve where pdf1(x,y)==pdf2(x,y) which is the decision boundary (discriminant). If you wish to define "nice" function you can do it simply by setting f(x,y) = sgn( pdf1(x,y) - pdf2(x,y) ), and plotting its contour plot will result in exact same discriminant.

查看更多
登录 后发表回答