# Drill 12 XOR using two hidden units

Subject: Deep Learning

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/#tee/read/17/tee-c17-s12

Canonical: https://deep-learning-study-room.vercel.app/read/dl/tee/section/tee-c17-s12/

## Question

**Question.** Use h1 = step(x1+x2−0.5), h2 = step(x1+x2−1.5), output = step(h1−2h2−0.5), step(z) = 1 if z≥0. Find all four outputs.

## Answer — step by step

### Given

h₁ = step(x₁+x₂−0.5); h₂ = step(x₁+x₂−1.5).

Output = step(h₁−2h₂−0.5).

step(z) = 1 when z ≥ 0, otherwise 0.

### To find

Calculate hidden values and output for 00, 01, 10 and 11.

### Formula — which one and why

**Threshold logic.** Compute the weighted sum for every binary input combination and apply the threshold rule exactly. Hidden neurons can provide separate threshold decisions before the output combines them.

step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.



$$
z=\sum_iw_ix_i+b
$$





$$
\operatorname{step}(z)=\begin{cases}1&z\ge0\\0&z<0\end{cases}
$$



**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.

### Solution — step by step

### Meaning of the given network

XOR should output 1 when exactly one input is 1, and 0 when the inputs match. The first hidden unit detects “at least one input is 1”; the second detects “both inputs are 1”. The output combines these detections.



$$
h_1=\operatorname{step}(x_1+x_2-0.5)
$$





$$
h_2=\operatorname{step}(x_1+x_2-1.5)
$$





$$
o=\operatorname{step}(h_1-2h_2-0.5)
$$



For this question, step returns 1 at nonnegative input and 0 at negative input.

**Step 1: Input pair 0, 0.**



$$
z_{h_1}=0+0-0.5=-0.5\Rightarrow h_1=0
$$





$$
z_{h_2}=0+0-1.5=-1.5\Rightarrow h_2=0
$$





$$
z_o=0-2(0)-0.5=-0.5\Rightarrow o=0
$$



**Step 2: Input pair 0, 1.**



$$
z_{h_1}=0+1-0.5=0.5\Rightarrow h_1=1
$$





$$
z_{h_2}=0+1-1.5=-0.5\Rightarrow h_2=0
$$





$$
z_o=1-2(0)-0.5=0.5\Rightarrow o=1
$$



**Step 3: Input pair 1, 0.**



$$
z_{h_1}=1+0-0.5=0.5\Rightarrow h_1=1
$$





$$
z_{h_2}=1+0-1.5=-0.5\Rightarrow h_2=0
$$





$$
z_o=1-2(0)-0.5=0.5\Rightarrow o=1
$$



**Step 4: Input pair 1, 1.**



$$
z_{h_1}=1+1-0.5=1.5\Rightarrow h_1=1
$$





$$
z_{h_2}=1+1-1.5=0.5\Rightarrow h_2=1
$$





$$
z_o=1-2(1)-0.5=-1.5\Rightarrow o=0
$$



**Final truth table:** 00 → 0; 01 → 1; 10 → 1; 11 → 0.
