2
$\begingroup$

I am was preparing for a pattern recognition exam and in a mock exam the question below was asked. I've also included my attempt, but I couldn't really figure out how to find the weights to the output layer. Could you please tell me whether what I've done is correct and guide me how to find the output layer weights?

Question

The neural network is supposed to give boundary decision between classes depicted in the diagram below. Please fill in missing neuron’s weights in the net schema at the bottom of the page. The network should produce 1 for ‘*’ class. Neurons have binary bipolar activation function (i.e. their output is -1 or 1). decision boundary neural-network


My attempt

I thought that each line segment, which I will now refer as left, middle (the vertical one) and right line segments could be represented with one of the neurons from the network. So I took the decision boundary as,

$$ \begin{align*} & w_1x_1 + w_2x_2 - b = 0 \tag 1 \\ & x_2 = - \frac{w_1}{w_2} x_1 + \frac{b}{w_2} \tag 2 \end{align*} $$

Left Line Segment (LLS)

I've chosen 2 points from the Figure above that are on the left line segment so that I could calculate the slope of it which I will later use to get the slope of the weight vector.

$$ \begin{align*} P_1 &= (\phantom- 2, 6)\\ P_2 &= (-6, 2) \\[1ex] m_{LLS} &= \frac{6 - 2}{2 - (-6)} = \frac{1}{2} \end{align*} $$

Since our weight vector is supposed to be perpendicular to the decision boundary I can then do,

$$ m_{w_{LLS}} = - \frac{1}{m_{LLS}} = - \frac{2}{1} $$

which means that,

$$ m_{w_{LLS}} = - \frac{2}{1} = \frac{w_{LLS_{2}} - 0}{w_{LLS_{1}} - 0} = \frac{w_{LLS_{2}}}{w_{LLS_{1}}} \\ $$

Since the weight vector should be pointing in the direction of the positive (red) class I took the $w_{LLS}$ vector as $$ \begin{align*} & w_{LLS_{1}} = \phantom- 1 \\ & w_{LLS_{2}} = -2 \end{align*} $$

Substituting the weight values and $P_1$ in Eq. (2) $$ \begin{align*} & 6 = \frac{1}{2} 2 + \frac{b}{2} \\[1ex] & b = 10 \end{align*} $$

In the end, for the left line segment, we have got a weight vector of $\begin{bmatrix} \phantom- 1 \\ -2 \end{bmatrix}$ and a bias of 10.

Middle Line Segment (MLS)

For the middle line segment, since it's a vertical line we know that $w_{MLS_{2}}$ should already be 0 so that we get a horizontal weight vector that is perpendicular to the MLS.

Since the weight vector should point to the positive (red) samples, I thought that $w_{MLS_{1}}$ should be -1 so that we get a horizontal weight vector pointing to the positive samples.

After figuring out $w_{MLS}$ we can calculate the bias by substituting weights and a point that's on MLS in Eq. 1.

\begin{align} P &= (2, 6) \\[1ex] -1x_1 + 0x_2 - b &= 0 \\ -2 + 0 - b &= 0 \\ b &= -2 \end{align}

In the end, for the left line segment, we have got a weight vector of $\begin{bmatrix}-1\\ \phantom- 0\end{bmatrix}$ and a bias of -2.

Right Line Segment (RLS)

Two points on the right line segment are,

$$ \begin{align*} & P_1 = (2, -6) \\ & P_2 = (8, -2) \end{align*} $$

Slope of the RLS is,

$$ m_{RLS} = \frac{-2 - (-6)}{8 - 2} = \frac{2}{3}\\ $$

Hence the slope of the weight vector $w_{RLS}$ should be

$$ m_{w_{RLS}} = - \frac{3}{2} = \frac{w_{RLS_{2}} - 0}{w_{RLS_{1}} - 0} = \frac{w_{RLS_{2}}}{w_{RLS_{1}}} $$

Since the weight vector should point to the positive (red) samples we choose $w_{RLS_{2}}$ to be negative and $w_{RLS_{1}}$ to be positive so that we get

$$ w_{RLS_{1}} = \phantom- 2 \\ w_{RLS_{2}} = -3 $$

It's shown in the network figure above that our $w_{RLS_{1}}$ should be 1 so we get a new scaled weight vector of $\begin{bmatrix}1\\ \frac{-3}{2}\end{bmatrix}$.

To find the bias we substitute weights and $P_1$ in Eq. (1)

$$ 1 x_1 + \frac{-3}{2}x_2 - b = 0 \\ 2 + \frac{-3}{2}(-6) - b = 0 \\ b = 11 $$

Finally

If I substitute all the values in the network Figure above, I get

Final network

Where I am Stuck

As I mentioned in the beginning, I couldn't figure out how to find the output layer weights. I don't know what I should be looking for. I would appreciate your help on that.

$\endgroup$

1 Answer 1

1
$\begingroup$

The last layer should act like a logic gate. To output $1$ for red class, you need either lower part of RLS (-1 is outputted) or, left side of MLS (-1 is outputted) and lower part of LLS (1 outputted) together. To be more precise, you need the following to hold: $$R=-1\cup \{M=-1\cap L=1\}$$

There are several solutions but it can be achieved by $w_{1}=-0.5, w_2=-1.1, w_3=0.5$. Basically, we try to keep $R$'s weight more so that if it's $-1$, others don't matter. If not, others will produce positive result only when they match with the and condition.

$\endgroup$
5
  • $\begingroup$ You said "you need either lower part of RLS (-1 is outputted)...", but if the point is on the lower part of RLS, +1 is outputted, am I missing something? The same for the MLS part. So shouldn't it be like $R = 1 \cup \{ M = 1 \cap L = 1\} $ so we get a +1 when either RLS outputs +1 or MLS and LLS output +1 together. $\endgroup$ Commented Jan 20, 2021 at 20:49
  • 1
    $\begingroup$ For RLS, (0,0) is on the upper side, and when I input it to your weights (middle one), the sum is $11$, which maps to $1$. So, the lower part should output $-1$. I might be missing some of your terminology by the way since I didn't go over all the details in your derivation. $\endgroup$
    – gunes
    Commented Jan 20, 2021 at 20:52
  • $\begingroup$ Oh I think I have a mistake in my solution. I had the decision boundary formula as $w_1x_1 + w_2x_2 -b = 0$ and with this formula, for RLS I got the bias as 11. I think I should've taken the bias in the formula as $+b$ instead of $-b$. But why does that make a difference? $\endgroup$ Commented Jan 20, 2021 at 20:59
  • $\begingroup$ Ok, I thought of it as $+b$ by looking at your neurons only, so the figure above should have $2, -11, -10$ as bias respectively. Negating them results in negating the signs of $R,M,L$, i.e. we need $R=1\cup \{M=1\cap L=-1\}$, (not $L=1$), then the weights of the last layer can be arranged to conform with this. $\endgroup$
    – gunes
    Commented Jan 20, 2021 at 23:00
  • $\begingroup$ The formula for decision boundary was the same for all the lines, which is $w_1x_1 + w_2x_2 - b = 0$. So shouldn't we negate the bias of the LLS as well? So in that case $L$ should be equal to $1$ as well? Sorry for the confusion. I understand the logic anyway, thank you so much! $\endgroup$ Commented Jan 21, 2021 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.