1

I am trying to plot the decision boundary of a perceptron algorithm and am really confused about a few things. My input instances are in the form [(x1,x2),target_Value], basically a 2-d input instance and a 2 class target_value [1 or 0].

My weight vector hence is in the form: [w1,w2] Now I have to incorporate an additional bias parameter w0 and hence my weight vector becomes a 3x1 vector? is it 1x3 vector? I think it should be 1x3 since a vector has only 1 row and n columns.

Now let's say I instantiate [w0,w1,w2] to random values, how would I plot the decision boundary for this? Meaning what does w0 signify here? Is w0/norm(w) the distance of the decision region from the origin? If so how do I capture this and plot it in python using matplotlib.pyplot or its matlab equivalent? I would really appreciate even a little help regarding this matter.

from pylab import norm
import matplotlib.pyplot as plt

n = norm(weight_vector) #this is of the form [w0,w1,w2], w0 is bias parameter
ww = weight_vector/n   #unit vector in the direction of weight_vector
ww1 = [ww[1],-ww[0]]
ww2 = [-ww[1],ww[0]]
plot([ww1[0], ww2[0]],[ww1[1], ww2[1]],'--k')

Here I want to incorporate the w0 parameter to indicate the distance of the displacement of the weight vector from the origin since that's what w0/norm(w) indicates?

When I plot the vector as mentioned in the comments below I get a vector of really small length, how would it be possible for me to extend this decision boundary in both directions?

John
  • 1,335
  • 12
  • 17
user2826591
  • 11
  • 1
  • 3

1 Answers1

3

As your decision function is simply sgn(w1*x+w2*y+w3) then the decision boundary equation is a line with canonical form w1*x + w2*y + w3 = 0.

|w3|/||w|| is the distance from the origin, w3 itself does not have a good geometrical interpretation (as long as w is not unit-length).

In order to plot line with such equation you can simply draw a line through (0,-w3/w2) and (-w3/w1,0) (assuming that both w1 and w2 are non-zero)

lejlot
  • 64,777
  • 8
  • 131
  • 164
  • yes w1 and w2 are non-zero, thank you so much for your input. This clarified the concept in my head. – user2826591 Sep 28 '13 at 16:31
  • Glad I could help. Remember to mark answer as a correct one. – lejlot Sep 28 '13 at 16:35
  • but wouldn't the decision boundary be orthogonal to w? I am unable to tell whether we are capturing that here? – user2826591 Sep 28 '13 at 16:38
  • w is a **normal** to the decision boundary, so it is an orthogonal vector. The canonical form of line equation uses the normal to express the line. Consider simple example with `y=-x`, if you write it in canonical form you get `1*x+1*y=0`, which leads to `w=[1,1]` which is perpendicular to the `y=-x` – lejlot Sep 28 '13 at 16:43
  • ya so the vector [w1,w2,w3] is perpendicular to the vector dot(w,x) -> w1x1+w2x2+w3(1) where w3 is bias. Ok I understand thanks for your patience and simple explanation leijlot. – user2826591 Sep 28 '13 at 16:48
  • What if the decision boundary passes through (0,0)? – sfotiadis Oct 13 '16 at 10:50
  • Nothing, there is nothing special about 0,0. The only problem is of it is perpendicular to one of the axes, then you have to derive different equation, but it is easy to compute – lejlot Oct 13 '16 at 10:53