# R23 Q5b

Subject: Deep Learning

Exam: TEE

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

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

## Question

**Question (10 marks).** Justify multiple ANN layers. Design a fraudulent/non-fraudulent transaction classifier for 10,000 samples with 4 features; choose layers/units and count parameters.

## Answer — step by step

### Given

10,000 samples; 4 features per sample; two target classes: fraudulent/non-fraudulent.

Hidden layer sizes are design choices, not fixed in the question.

### To find

Explain multiple layers, propose an appropriate classifier and count parameters for that explicit design.

### Formula — which one and why

**Dense-layer parameters.** Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.

n\_in = incoming features; n\_out = receiving neurons. The input layer itself has no learned receiving weights or biases.



$$
P=(n_{\mathrm{in}}+1)n_{\mathrm{out}}
$$



**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.

### Solution — step by step

A single perceptron forms a weighted sum and applies a threshold. Its decision boundary is linear: w·x+b = 0. It can learn linearly separable patterns such as AND and OR under suitable learning conditions, but cannot represent XOR with one linear separator.

![Opposite corners for XOR cannot be split by one straight line](https://deep-learning-study-room.vercel.app/assets/figures/xor.svg)

Diagram: Opposite corners for XOR cannot be split by one straight line. Labels: x1 | x2 | 0 | 1 | 1 | 0 | XOR labels occupy opposite corners | 0 | 1 | 0 | 1 | One straight decision boundary cannot separate the two classes.

Opposite corners for XOR cannot be split by one straight line Tap the diagram to enlarge.

For binary AND, w₁ = w₂ = 1 and b = −1.5 give preactivations −1.5, −0.5, −0.5 and 0.5 for 00, 10, 01 and 11. A step that returns 1 at nonnegative inputs produces 0,0,0,1.

For XOR, use h₁ = step(x₁+x₂−0.5) for OR and h₂ = step(x₁+x₂−1.5) for AND. Then XOR = step(h₁−2h₂−0.5). For inputs 00,01,10,11, the hidden pairs are (0,0), (1,0), (1,0), (1,1), producing 0,1,1,0. XNOR = step(−h₁+2h₂+0.5), producing 1,0,0,1. This is a multilayer construction, not a claim that a single perceptron solves XOR.

A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.

**Chosen design:** 4 → 8 → 4 → 1 with ReLU hidden layers, one sigmoid output and binary cross-entropy. Hidden widths are explicit design assumptions.

Architecture: 4 → 8 → 4 → 1. Each non-input neuron has one bias.

### Layer 4 → 8

**Step 1: count connections.**



$$
4(8)=32
$$



**Step 2: count receiving-neuron biases.**

There are 8 receiving neurons, so 8 biases.

**Step 3: add weights and biases.**



$$
32+8=40
$$



### Layer 8 → 4

**Step 1: count connections.**



$$
8(4)=32
$$



**Step 2: count receiving-neuron biases.**

There are 4 receiving neurons, so 4 biases.

**Step 3: add weights and biases.**



$$
32+4=36
$$



### Layer 4 → 1

**Step 1: count connections.**



$$
4(1)=4
$$



**Step 2: count receiving-neuron biases.**

There are 1 receiving neurons, so 1 biases.

**Step 3: add weights and biases.**



$$
4+1=5
$$



**Total = 81**. Input values and activations are not trainable parameters.

Use stratified train/validation/test partitions; handle class imbalance using appropriate training weights and evaluate precision/recall or a suitable decision threshold alongside accuracy. More layers are useful only if they learn needed nonlinear structure; the problem statement does not prescribe one uniquely correct architecture.

### Verify input (0,0)

**Step 1: calculate hidden OR preactivation.**



$$
z_1=0+0-0.5=-0.5
$$



**Step 2: apply its threshold.**



$$
h_1=0
$$



**Step 3: calculate hidden AND preactivation.**



$$
z_2=0+0-1.5=-1.5
$$



**Step 4: apply its threshold.**



$$
h_2=0
$$



**Step 5: calculate XOR output preactivation.**



$$
z_{XOR}=0-2(0)-0.5=-0.5
$$



**Step 6: apply the XOR threshold.**



$$
y_{XOR}=0
$$



**Step 7: calculate XNOR output preactivation.**



$$
z_{XNOR}=-0+2(0)+0.5=0.5
$$



**Step 8: apply the XNOR threshold.**



$$
y_{XNOR}=1
$$



### Verify input (0,1)

**Step 1: calculate hidden OR preactivation.**



$$
z_1=0+1-0.5=0.5
$$



**Step 2: apply its threshold.**



$$
h_1=1
$$



**Step 3: calculate hidden AND preactivation.**



$$
z_2=0+1-1.5=-0.5
$$



**Step 4: apply its threshold.**



$$
h_2=0
$$



**Step 5: calculate XOR output preactivation.**



$$
z_{XOR}=1-2(0)-0.5=0.5
$$



**Step 6: apply the XOR threshold.**



$$
y_{XOR}=1
$$



**Step 7: calculate XNOR output preactivation.**



$$
z_{XNOR}=-1+2(0)+0.5=-0.5
$$



**Step 8: apply the XNOR threshold.**



$$
y_{XNOR}=0
$$



### Verify input (1,0)

**Step 1: calculate hidden OR preactivation.**



$$
z_1=1+0-0.5=0.5
$$



**Step 2: apply its threshold.**



$$
h_1=1
$$



**Step 3: calculate hidden AND preactivation.**



$$
z_2=1+0-1.5=-0.5
$$



**Step 4: apply its threshold.**



$$
h_2=0
$$



**Step 5: calculate XOR output preactivation.**



$$
z_{XOR}=1-2(0)-0.5=0.5
$$



**Step 6: apply the XOR threshold.**



$$
y_{XOR}=1
$$



**Step 7: calculate XNOR output preactivation.**



$$
z_{XNOR}=-1+2(0)+0.5=-0.5
$$



**Step 8: apply the XNOR threshold.**



$$
y_{XNOR}=0
$$



### Verify input (1,1)

**Step 1: calculate hidden OR preactivation.**



$$
z_1=1+1-0.5=1.5
$$



**Step 2: apply its threshold.**



$$
h_1=1
$$



**Step 3: calculate hidden AND preactivation.**



$$
z_2=1+1-1.5=0.5
$$



**Step 4: apply its threshold.**



$$
h_2=1
$$



**Step 5: calculate XOR output preactivation.**



$$
z_{XOR}=1-2(1)-0.5=-1.5
$$



**Step 6: apply the XOR threshold.**



$$
y_{XOR}=0
$$



**Step 7: calculate XNOR output preactivation.**



$$
z_{XNOR}=-1+2(1)+0.5=1.5
$$



**Step 8: apply the XNOR threshold.**



$$
y_{XNOR}=1
$$



**Final answer:** XOR = [0,1,1,0]; XNOR = [1,0,0,1] for 00,01,10,11. The hidden nonlinear units make this possible.
