Deep Learning · TEE · section
R24 Q2a
Re examination February 2024 fully solved
Question
Question (10 marks). A 4 → 4 → 1 sigmoid network has input [.4,.3,.5,−.4]. The printed W₁ is shown below, W₂ = [.5,.7,−.6,.2]; hidden bias 0.6, output bias 0.2, target 0.9, η = .5. Compute mean squared error and update the connection h₁ → output. In the graph θ ij connects input i to hidden j.
Answer — step by step
Given
A 4 → 4 → 1 sigmoid network has input [.4,.3,.5,−.4].
The printed W₁ is printed with the question, W₂ = [.5,.7,−.6,.2].
hidden bias 0.6, output bias 0.2, target 0.9, η = .5.
To find
Find all preactivations, hidden activations and final outputs. Calculate MSE and its output derivatives. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.
Formula — which one and why
Forward propagation. Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.
x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.
z_h=W_1x+b_1h=f_1(z_h)z_o=W_2h+b_2o=f_2(z_o)Yaad rakhne ka cue: Pehli layer ka activated output hi agli layer ka input hai.
Mean squared loss. Average the squared scalar prediction errors. The derivative retains the factor 2/n; n must count the outputs included in this mean.
n = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.
L=\frac1n\sum_j(o_j-y_j)^2\frac{\partial L}{\partial o_j}=\frac2n(o_j-y_j)Yaad rakhne ka cue: MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.
Sigmoid and its slope. Use sigmoid when the neuron is specified to squash its preactivation into (0,1). Once its output is known, its derivative needs only output × (1−output).
z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.
p=\frac{1}{1+e^{-z}}\frac{dp}{dz}=p(1-p)Yaad rakhne ka cue: Sigmoid output p; uska slope p × (1−p).
Backpropagation. The loss tells us how each output must change. Multiply by that neuron’s activation slope to obtain its delta. A weight gradient is receiving delta × sending value. Hidden deltas must include every outgoing path.
δ (delta) = derivative of loss with respect to a neuron’s preactivation; f′ = activation derivative; aᵢ = sending activation; Wⱼᵢ = connection weight. Use the exact loss scaling in the question.
\delta_{o_j}=\frac{\partial L}{\partial o_j}f_o\prime(z_{o_j})\delta_{h_i}=f_h\prime(z_{h_i})\sum_jW_{ji}^{(2)}\delta_{o_j}\frac{\partial L}{\partial W_{ji}}=\delta_ja_i\frac{\partial L}{\partial b_j}=\delta_jW_{ji,\mathrm{new}}=W_{ji}-\eta\frac{\partial L}{\partial W_{ji}}Yaad rakhne ka cue: Receiving delta × sending value = us connection ka gradient.
Solution — step by step
Orientation: the source rows list sending inputs, so use each COLUMN to form a receiving hidden neuron. In our usual column-input convention this means using the transpose of printed W₁. The loss is one-output MSE = (o−0.9)², so its derivative includes 2.
Step 1 map the arrows. Each row of W₁ receives all inputs; each row of W₂ receives all hidden outputs. Bias is added once per receiving neuron. All gradients below use the OLD weights from this same forward pass.
Hidden neuron 1:
z_{h_1} = (0.8 \times 0.4) + (-0.5 \times 0.3) + (0.1 \times 0.5) + (-0.2 \times -0.4) + (0.6) = 0.9h_{1}=\frac{1}{1+e^{-(0.9)}}=0.710949503Hidden neuron 2:
z_{h_2} = (0.2 \times 0.4) + (0.4 \times 0.3) + (0.2 \times 0.5) + (0.5 \times -0.4) + (0.6) = 0.7h_{2}=\frac{1}{1+e^{-(0.7)}}=0.668187772Hidden neuron 3:
z_{h_3} = (0.3 \times 0.4) + (0.3 \times 0.3) + (-0.1 \times 0.5) + (0.5 \times -0.4) + (0.6) = 0.56h_{3}=\frac{1}{1+e^{-(0.56)}}=0.63645254Hidden neuron 4:
z_{h_4} = (0.4 \times 0.4) + (0.2 \times 0.3) + (0.2 \times 0.5) + (0.8 \times -0.4) + (0.6) = 0.6h_{4}=\frac{1}{1+e^{-(0.6)}}=0.645656306Output neuron 1:
\begin{aligned}z_{o_1}={}&0.5(0.710949503)+0.7(0.668187772)\\&-0.6(0.63645254)+0.2(0.645656306)+0.2\\={}&0.770465929\end{aligned}o_{1}=\frac{1}{1+e^{-(0.770465929)}}=0.683621675Step 2 loss convention. Use the explicitly requested one-output MSE, not half squared loss.
Prediction minus target = [-0.216378325]. Squared errors = [0.04681958]. Half-sum squared loss = 0.02340979; mean squared error = 0.04681958. These are different unless the number of output components makes the scale coincide.
Output delta 1:
\delta_{o_1} = 2 \times (0.683621675-0.9) \times 0.216283081 = -0.093597941The derivative is o(1−o).
Step 3 output weights. Gradient = receiving delta × sending activation. An output bias gradient equals its delta.
h1 → o1:
Subtract η × gradient = −0.033271705. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies its activation.
g_{1,1}^{(2)}=\frac{\partial L}{\partial W^{(2)}_{1,1}}=\delta_{o_1}h_1g_{1,1}^{(2)}=(-0.093597941)\times(0.710949503)\approx -0.06654341Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(2)}_{1,1,\mathrm{new}}=0.5-0.5(-0.06654341)\approx 0.533271705h2 → o1:
Subtract η × gradient = −0.0312705. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies its activation.
g_{1,2}^{(2)}=\frac{\partial L}{\partial W^{(2)}_{1,2}}=\delta_{o_1}h_2g_{1,2}^{(2)}=(-0.093597941)\times(0.668187772)\approx -0.062541Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(2)}_{1,2,\mathrm{new}}=0.7-0.5(-0.062541)\approx 0.7312705h3 → o1:
Subtract η × gradient = −0.029785324. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies its activation.
g_{1,3}^{(2)}=\frac{\partial L}{\partial W^{(2)}_{1,3}}=\delta_{o_1}h_3g_{1,3}^{(2)}=(-0.093597941)\times(0.63645254)\approx -0.059570648Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(2)}_{1,3,\mathrm{new}}=-0.6-0.5(-0.059570648)\approx -0.570214676h4 → o1:
Subtract η × gradient = −0.03021605. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies its activation.
g_{1,4}^{(2)}=\frac{\partial L}{\partial W^{(2)}_{1,4}}=\delta_{o_1}h_4g_{1,4}^{(2)}=(-0.093597941)\times(0.645656306)\approx -0.060432101Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(2)}_{1,4,\mathrm{new}}=0.2-0.5(-0.060432101)\approx 0.230216051Step 4 hidden deltas. A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.
Hidden 1 downstream contribution:
Calculate each outgoing path using the old outgoing weight and that output's delta.
Multiply within each path. Add the resulting contributions at the shared hidden neuron.
Contribution from output 1.
C_1=(0.5)\times(-0.093597941)\approx -0.04679897Accumulate the contributions, then apply the hidden activation derivative below.
\text{Sum}=C_1\approx -0.046798971\delta_{h_1} = -0.046798971 \times 0.205500307 = -0.009617203Hidden 2 downstream contribution:
Calculate each outgoing path using the old outgoing weight and that output's delta.
Multiply within each path. Add the resulting contributions at the shared hidden neuron.
Contribution from output 1.
C_1=(0.7)\times(-0.093597941)\approx -0.065518559Accumulate the contributions, then apply the hidden activation derivative below.
\text{Sum}=C_1\approx -0.065518559\delta_{h_2} = -0.065518559 \times 0.221712873 = -0.014526308Hidden 3 downstream contribution:
Calculate each outgoing path using the old outgoing weight and that output's delta.
Multiply within each path. Add the resulting contributions at the shared hidden neuron.
Contribution from output 1.
C_1=(-0.6)\times(-0.093597941)\approx 0.056158765Accumulate the contributions, then apply the hidden activation derivative below.
\text{Sum}=C_1\approx 0.056158765\delta_{h_3} = 0.056158765 \times 0.231380704 = 0.012994055Hidden 4 downstream contribution:
Calculate each outgoing path using the old outgoing weight and that output's delta.
Multiply within each path. Add the resulting contributions at the shared hidden neuron.
Contribution from output 1.
C_1=(0.2)\times(-0.093597941)\approx -0.018719588Accumulate the contributions, then apply the hidden activation derivative below.
\text{Sum}=C_1\approx -0.018719588\delta_{h_4} = -0.018719588 \times 0.22878424 = -0.004282747Step 5 input weights. Multiply the hidden delta by the corresponding raw input, not by the hidden output.
x1 → h1:
Subtract η × gradient = −0.00192344. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{1,1}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{1,1}}=\delta_{h_1}x_1g_{1,1}^{(1)}=(-0.009617203)\times(0.4)\approx -0.003846881Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{1,1,\mathrm{new}}=0.8-0.5(-0.003846881)\approx 0.801923441x2 → h1:
Subtract η × gradient = −0.00144258. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{1,2}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{1,2}}=\delta_{h_1}x_2g_{1,2}^{(1)}=(-0.009617203)\times(0.3)\approx -0.002885161Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{1,2,\mathrm{new}}=-0.5-0.5(-0.002885161)\approx -0.49855742x3 → h1:
Subtract η × gradient = −0.0024043. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{1,3}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{1,3}}=\delta_{h_1}x_3g_{1,3}^{(1)}=(-0.009617203)\times(0.5)\approx -0.004808601Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{1,3,\mathrm{new}}=0.1-0.5(-0.004808601)\approx 0.102404301x4 → h1:
Subtract η × gradient = 0.00192344. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{1,4}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{1,4}}=\delta_{h_1}x_4g_{1,4}^{(1)}=(-0.009617203)\times(-0.4)\approx 0.003846881Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{1,4,\mathrm{new}}=-0.2-0.5(0.003846881)\approx -0.201923441x1 → h2:
Subtract η × gradient = −0.002905262. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{2,1}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{2,1}}=\delta_{h_2}x_1g_{2,1}^{(1)}=(-0.014526308)\times(0.4)\approx -0.005810523Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{2,1,\mathrm{new}}=0.2-0.5(-0.005810523)\approx 0.202905262x2 → h2:
Subtract η × gradient = −0.002178946. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{2,2}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{2,2}}=\delta_{h_2}x_2g_{2,2}^{(1)}=(-0.014526308)\times(0.3)\approx -0.004357892Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{2,2,\mathrm{new}}=0.4-0.5(-0.004357892)\approx 0.402178946x3 → h2:
Subtract η × gradient = −0.003631577. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{2,3}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{2,3}}=\delta_{h_2}x_3g_{2,3}^{(1)}=(-0.014526308)\times(0.5)\approx -0.007263154Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{2,3,\mathrm{new}}=0.2-0.5(-0.007263154)\approx 0.203631577x4 → h2:
Subtract η × gradient = 0.002905262. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{2,4}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{2,4}}=\delta_{h_2}x_4g_{2,4}^{(1)}=(-0.014526308)\times(-0.4)\approx 0.005810523Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{2,4,\mathrm{new}}=0.5-0.5(0.005810523)\approx 0.497094738x1 → h3:
Subtract η × gradient = 0.002598811. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{3,1}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{3,1}}=\delta_{h_3}x_1g_{3,1}^{(1)}=(0.012994055)\times(0.4)\approx 0.005197622Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{3,1,\mathrm{new}}=0.3-0.5(0.005197622)\approx 0.297401189x2 → h3:
Subtract η × gradient = 0.001949108. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{3,2}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{3,2}}=\delta_{h_3}x_2g_{3,2}^{(1)}=(0.012994055)\times(0.3)\approx 0.003898216Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{3,2,\mathrm{new}}=0.3-0.5(0.003898216)\approx 0.298050892x3 → h3:
Subtract η × gradient = 0.003248514. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{3,3}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{3,3}}=\delta_{h_3}x_3g_{3,3}^{(1)}=(0.012994055)\times(0.5)\approx 0.006497027Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{3,3,\mathrm{new}}=-0.1-0.5(0.006497027)\approx -0.103248514x4 → h3:
Subtract η × gradient = −0.002598811. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{3,4}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{3,4}}=\delta_{h_3}x_4g_{3,4}^{(1)}=(0.012994055)\times(-0.4)\approx -0.005197622Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{3,4,\mathrm{new}}=0.5-0.5(-0.005197622)\approx 0.502598811x1 → h4:
Subtract η × gradient = −0.00085655. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{4,1}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{4,1}}=\delta_{h_4}x_1g_{4,1}^{(1)}=(-0.004282747)\times(0.4)\approx -0.001713099Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{4,1,\mathrm{new}}=0.4-0.5(-0.001713099)\approx 0.400856549x2 → h4:
Subtract η × gradient = −0.000642412. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{4,2}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{4,2}}=\delta_{h_4}x_2g_{4,2}^{(1)}=(-0.004282747)\times(0.3)\approx -0.001284824Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{4,2,\mathrm{new}}=0.2-0.5(-0.001284824)\approx 0.200642412x3 → h4:
Subtract η × gradient = −0.001070686. This weight increases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{4,3}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{4,3}}=\delta_{h_4}x_3g_{4,3}^{(1)}=(-0.004282747)\times(0.5)\approx -0.002141373Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{4,3,\mathrm{new}}=0.2-0.5(-0.002141373)\approx 0.201070687x4 → h4:
Subtract η × gradient = 0.00085655. This weight decreases.
The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.
The receiving neuron supplies the delta; the sending neuron supplies the input value.
g_{4,4}^{(1)}=\frac{\partial L}{\partial W^{(1)}_{4,4}}=\delta_{h_4}x_4g_{4,4}^{(1)}=(-0.004282747)\times(-0.4)\approx 0.001713099Apply the learning rate to this gradient and subtract the result from the old weight.
W^{(1)}_{4,4,\mathrm{new}}=0.8-0.5(0.001713099)\approx 0.799143451Step 6 bias updates. A bias receives a constant input 1, so its gradient equals the corresponding delta. Use the same old forward pass and learning rate as the weight updates.
b_{h_1,\mathrm{new}}=0.6-0.5(-0.009617203)=0.604808601b_{h_2,\mathrm{new}}=0.6-0.5(-0.014526308)=0.607263154b_{h_3,\mathrm{new}}=0.6-0.5(0.012994055)=0.593502972b_{h_4,\mathrm{new}}=0.6-0.5(-0.004282747)=0.602141373b_{o_1,\mathrm{new}}=0.2-0.5(-0.093597941)=0.246798971These are independent per-neuron biases. If the question fixes biases, keep them fixed. If it specifies a single tied bias, add all deltas sharing that bias before updating it.
Required result: output 0.683621675, MSE 0.046819580, h₁ → output new weight 0.533271705. If instead each printed row is assumed to receive inputs, the conditional alternative is output 0.681090691, MSE 0.047921285 and updated weight 0.534478309. Explain the arrow convention rather than mixing these results.